20180518VSTO多簿单表汇总外接程序按钮
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多簿单表汇总外接程序按钮的更多相关文章
- 20180518VSTO多簿单表汇总
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...
- Hadoop工程师面试题(1)--MapReduce实现单表汇总统计
数据源格式描述: 输入t1.txt源数据,数据文件分隔符"*&*",字段说明如下: 字段序号 字段英文名称 字段中文名称 字段类型 字段长度 1 TIME_ID 时间(到时 ...
- SQL数据查询之——单表查询
一.SQL数据查询的一般格式 数据查询是数据库的核心操作.SQL提供了SELECT语句进行数据查询,其一般格式为: SELECT [ALL | DISTINCT]<目标列表达式>[,< ...
- HTML的表单标签汇总
HTML的表单标签汇总 表单的元素格式: 1. 账号.密码.提交.重置 语法: <p>账号:<input type="text" name="usern ...
- 2.Mybatis入门程序(单表的增删改成)
这里讲的单表的增删改查,是由mapper代理的增删改查,先来看看步骤: 1.jar包的导入 2.配置全局的配置文件 3.建立接口 4.编写mapper.xml 5.测试 工程结构:这个你们自己可以调整 ...
- 不使用left-join等多表关联查询,只用单表查询和Java程序,简便实现“多表查询”效果
上次我们提到,不使用left-loin关联查询,可能是为了提高效率或者配置缓存,也可以简化一下sql语句的编写.只写单表查询,sql真得太简单了.问题是,查询多个表的数据还是非常需要的. 因此,存在这 ...
- SAP 表汇总
SAP 表整理:VBKPF-预制凭证抬头表: VBKPF-预制凭证抬头表 VBKPF-预制凭证抬头表 VBSEG-预制凭证行项目表: VBSEG-预制凭证行项目表 VBSEG-预制凭证行项目表 VBS ...
- MySQL单表百万数据记录分页性能优化
背景: 自己的一个网站,由于单表的数据记录高达了一百万条,造成数据访问很慢,Google分析的后台经常报告超时,尤其是页码大的页面更是慢的不行. 测试环境: 先让我们熟悉下基本的sql语句,来查看下我 ...
- hibernate单表junit测试
首先,创建java project ,导入需要的jar包 添加hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!D ...
随机推荐
- 【python--函数解读】
1.strip()函数:用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列(包括'\n', '\r', '\t', ' ') 注意: 该方法只能删除开头或是结尾的字符,不能删除中间部分的 ...
- 在Linux系统安装Appium
安装sudo apt-get update sudo apt-get install nodejs sudo apt-get install npm npm install -g appium 卸载: ...
- Python3 tkinter基础 Button text,fg 按钮上显示的文字 文字的颜色
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- HDU - 1849 Rabbit and Grass 【Nim博弈】
Problem Description 大学时光是浪漫的,女生是浪漫的,圣诞更是浪漫的,但是Rabbit和Grass这两个大学女生在今年的圣诞节却表现得一点都不浪漫:不去逛商场,不去逛公园,不去和AC ...
- Jenkins serving Cake: our recipe for Windows
https://novemberfive.co/blog/windows-jenkins-cake-tutorial/ Where we started, or: why Cake took the ...
- 网络_TCP连接的建立与释放
三报文握手 1.概述 TCP是面向连接的协议.TCP建立连接的过程叫做握手,握手需要在客户和服务器之间交换三个TCP报文段,即我们说的"三次握手"(严格讲是一次握手过程中交换了三个 ...
- 【创建模式】--Singleton
设计模式之Singleton(单态) 单态定义: Singleton 模式主要作用是保证在Java应用程序中,一个类Class 只有一个实例存在. 在很多操作中,比如建立目录 数据库链接都需要这样的 ...
- springmvc上传zip文件并解压缩代码示例
<input type="file" id="file" name="file"> spring中的配置: <!-- ...
- 【译】第21节---Fluent API
原文:http://www.entityframeworktutorial.net/code-first/fluent-api-in-code-first.aspx 在前面的学习中.我们已经看到不同的 ...
- vue--存储
storage 一个存储库,它支持具有相同 api 的 sessionStorage 和 localStorage 安装和用法: storage 的 API: set(key,val) 用key和va ...