using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Diagnostics;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.IO; namespace GatherData
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{ } private void ButtonGather_Click(object sender, RibbonControlEventArgs e)
{
Excel.Application xlApp = Globals.ThisAddIn.Application; Excel.Workbook wb = xlApp.ActiveWorkbook;
Excel.Worksheet sht = (Excel.Worksheet)wb.ActiveSheet;
sht.Cells.Clear();
TimeSpan StartTime = new TimeSpan(DateTime.Now.Ticks); ;
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)
{
StartTime = new TimeSpan(DateTime.Now.Ticks);
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]);
} xlApp.StatusBar = "正在汇总第" + index + "个文件,请耐心等候!"; openWb.Close(false, Type.Missing, Type.Missing);
}
}
} xlApp.ScreenUpdating = true;
xlApp.DisplayAlerts = true;
xlApp.StatusBar = false;
TimeSpan EndTime = new TimeSpan(DateTime.Now.Ticks);
TimeSpan duration = StartTime.Subtract(EndTime).Duration(); MessageBox.Show("汇总完成,耗时:" +duration.Minutes.ToString()+"分"+ 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. SQL数据查询之——单表查询

    一.SQL数据查询的一般格式 数据查询是数据库的核心操作.SQL提供了SELECT语句进行数据查询,其一般格式为: SELECT [ALL | DISTINCT]<目标列表达式>[,< ...

  4. HTML的表单标签汇总

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

  5. 2.Mybatis入门程序(单表的增删改成)

    这里讲的单表的增删改查,是由mapper代理的增删改查,先来看看步骤: 1.jar包的导入 2.配置全局的配置文件 3.建立接口 4.编写mapper.xml 5.测试 工程结构:这个你们自己可以调整 ...

  6. 不使用left-join等多表关联查询,只用单表查询和Java程序,简便实现“多表查询”效果

    上次我们提到,不使用left-loin关联查询,可能是为了提高效率或者配置缓存,也可以简化一下sql语句的编写.只写单表查询,sql真得太简单了.问题是,查询多个表的数据还是非常需要的. 因此,存在这 ...

  7. SAP 表汇总

    SAP 表整理:VBKPF-预制凭证抬头表: VBKPF-预制凭证抬头表 VBKPF-预制凭证抬头表 VBSEG-预制凭证行项目表: VBSEG-预制凭证行项目表 VBSEG-预制凭证行项目表 VBS ...

  8. MySQL单表百万数据记录分页性能优化

    背景: 自己的一个网站,由于单表的数据记录高达了一百万条,造成数据访问很慢,Google分析的后台经常报告超时,尤其是页码大的页面更是慢的不行. 测试环境: 先让我们熟悉下基本的sql语句,来查看下我 ...

  9. hibernate单表junit测试

    首先,创建java project ,导入需要的jar包 添加hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!D ...

随机推荐

  1. MVC 自定义特性(验证用户登录session是否已经过期)

    新建一个类 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)] publ ...

  2. IDEA引入Gradle工程小记

    1.首先IDEA要在该工程Settings中配置本地安装的Gradle,配好其home目录,注意目录到根目录即可,不要到bin一级,否则提示错误,无法使用: 2.配置好后会自动侦测Gradle项目,点 ...

  3. Download and Installation of Kibana

    下载以及安装 https://www.elastic.co/downloads/kibana 1.Download and unzip Kibana 2. Open config/kibana.yml ...

  4. oracle单行函数 之 时间函数

    select  systemdate from dual --得到时间 select systemdate+300 from dual  --日期 +数字=日期,表示若干天之后的日期 select s ...

  5. C# 里调用vb的inputbox弹出窗

    https://blog.csdn.net/hutao1101175783/article/details/16800871 先对项目添加对Microsoft.VisualBasic的引用 Inter ...

  6. Codeforces 808G Anthem of Berland(KMP+基础DP)

    题意 给定一个字符串 \(s\) ,一个字符串 \(t\) ,其中 \(s\) 包含小写字母和 "?" ,\(t\) 只包含小写字母,现在把 \(s\) 中的问号替换成任意的小写字 ...

  7. Google advertiser api开发概述——批量处理

    批处理 大多数服务都提供同步 API,要求您发出请求然后等待响应,但 BatchJobService 允许您对多项服务执行批量操作,而无需等待操作完成. 与各服务的特定 mutate 操作不同,Bat ...

  8. Linux安装python3.7

    1.下载与解压 先到python官网: https://www.python.org/downloads/release/python-371/](https://www.python.org/dow ...

  9. 使用v-for循环写入html内容,每一项的数据的写入

    项目使用vue.js,在写某个dialog页面时,需要循环后台的数据(班级,班级学生名单,已选学生名单,发布时间,截止时间,答案显示等). 遇到的问题:循环绑定的值是相同的,而且改动一个值,其他ite ...

  10. layer 弹出层 回调函数调用 弹出层页面 函数

    1.项目中用到layer 弹出层,定义一个公用的窗口,问题来了窗口弹出来了,如何保存页面上的数据呢?疯狂百度之后,有了结果,赶紧记下. 2.自己定义的公共页面方法: layuiWindow: func ...