using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms; namespace GatherDataTool
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{ } private void ButtonGather_Click(object sender, RibbonControlEventArgs e)
{
TimeSpan StartTime = new TimeSpan(DateTime.Now.Ticks);
GatherDataTool.ThisWorkbook wb = Globals.ThisWorkbook;
Excel.Worksheet sht =(Excel.Worksheet)wb.ActiveSheet;
sht.Cells.Clear();
Excel.Application xlApp = wb.Application;
xlApp.ScreenUpdating = false;
xlApp.DisplayAlerts = false;
Excel.Workbook openWb;
Excel.Worksheet openSht;
Excel.Range rng;
int index = 0;
Office.FileDialog fd = xlApp.FileDialog[Office.MsoFileDialogType.msoFileDialogFolderPicker];
fd.InitialFileName = xlApp.ActiveWorkbook.Path;
if(fd.Show()==-1)
{
string folderPath = fd.SelectedItems.Item(1);
string[] filePaths = Directory.GetFiles(folderPath, "*.xls*");
foreach(string filepath in filePaths)
{
if(filepath!=wb.FullName)
{
// Debug.Print(filepath);
index++;
openWb = xlApp.Workbooks.Open(filepath);
openSht = openWb.Worksheets[1];
long endrow = openSht.Cells[openSht.Rows.Count,3].End(Excel.XlDirection.xlUp).Row;
if (index == 1)
{
rng = openSht.Range[openSht.Cells[1, 1], openSht.Cells[endrow, 17]];
rng.Copy(sht.Cells[1,1]);
}
else
{
rng = openSht.Range[openSht.Cells[3, 1], openSht.Cells[endrow, 17]];
long nextRow=sht.Cells[sht.Rows.Count,1].End(Excel.XlDirection.xlUp).Row+1;
rng.Copy(sht.Cells[nextRow, 1]);
}
openWb.Close(false, Type.Missing, Type.Missing);
}
}
} xlApp.ScreenUpdating = true;
xlApp.DisplayAlerts = true;
TimeSpan EndTime = new TimeSpan(DateTime.Now.Ticks);
TimeSpan duration = StartTime.Subtract(EndTime).Duration(); MessageBox.Show("汇总完成,耗时:" + duration.Seconds.ToString()+"秒!");
}
}
}

  

20180518VSTO多簿单表汇总的更多相关文章

  1. 20180518VSTO多簿单表汇总外接程序按钮

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...

  2. Hadoop工程师面试题(1)--MapReduce实现单表汇总统计

    数据源格式描述: 输入t1.txt源数据,数据文件分隔符"*&*",字段说明如下: 字段序号 字段英文名称 字段中文名称 字段类型 字段长度 1 TIME_ID 时间(到时 ...

  3. HTML的表单标签汇总

    HTML的表单标签汇总 表单的元素格式: 1. 账号.密码.提交.重置 语法: <p>账号:<input type="text" name="usern ...

  4. SQLServer学习笔记<>.基础知识,一些基本命令,单表查询(null top用法,with ties附加属性,over开窗函数),排名函数

    Sqlserver基础知识 (1)创建数据库 创建数据库有两种方式,手动创建和编写sql脚本创建,在这里我采用脚本的方式创建一个名称为TSQLFundamentals2008的数据库.脚本如下:   ...

  5. 单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式

    单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式     一 表结构如下:  万行 CREATE TABLE t_audit_operate_log (  Fid b ...

  6. T_SQL查询语句(一): 单表查询

    ############################################ 查询语句--SELECT ########################################## ...

  7. Python学习(三十四)—— Django之ORM之单表、联表操作

    一.单表查询API汇总 <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(**kw ...

  8. 20171113xlVba指定文件夹多簿多表分表合并150

    '2017年11月13日 'Next_Seven '功能:文件夹对话框指定文件夹下,合并(复制粘贴)每个Excel文件内的指定子表内容, '在名为"设置"的工作表A列 输入汇总子表 ...

  9. 单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式

    一 表结构如下:  万行 CREATE TABLE t_audit_operate_log (  Fid bigint(16) AUTO_INCREMENT,  Fcreate_time int(10 ...

随机推荐

  1. xlrd、xlwt 操作excel表格详解

    转自:https://www.cnblogs.com/jiablogs/p/9141414.html python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是 ...

  2. Bootstrap3基础 clearfix pull-left/right 辅助类样式 快速左右浮动

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  3. Cmder + Babun 打造 Windows 好用的终端工具

    Babun a windows shell you will love Babun features the following: Pre-configured Cygwin with a lot o ...

  4. debian下如何源码安装tmux

    一.源码安装ncurses库 1.1 获取源码 wget https://invisible-island.net/datafiles/release/ncurses.tar.gz tar xvf n ...

  5. ppoint的使用

    ppt中的所有东西都要看作是 "对象" . 对 "对象"的操作逻辑是: 单击, 右键单击,双击(右键的时候, 直接就右键, 不必先选中再右键操作) 在ppt中, ...

  6. SpringBoot 使用Mybatis-Plus

    简介 Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 特性 无侵入:Mybatis-Plus 在 My ...

  7. 关于msf反弹后门的免杀Tips

    msf是一个很强大的工具,我经常会在渗透用它来反弹shell,不过它生成的反弹后门会被不少杀软kill,这篇文章只是讲讲我在msf中一个简单的免杀小技巧 思路 我以前接触过一款python的远控,其实 ...

  8. 题解——POJ 2234 Matches Game

    这道题也是一个博弈论 根据一个性质 对于\( Nim \)游戏,即双方可以任取石子的游戏,\( SG(x) = x \) 所以直接读入后异或起来输出就好了 代码 #include <cstdio ...

  9. 使用路由传参时,query与params的区别!

    query 1:参数会在地址栏显示 2:参数不需要在路由的path后接:args1/:args2 3:获取参数用this.$route.query.args1 params 1:参数需要在路由的pat ...

  10. A successful Git branching model——经典篇

    A successful Git branching model In this post I present the development model that I’ve introduced f ...