20180518VSTO多簿单表汇总
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多簿单表汇总的更多相关文章
- 20180518VSTO多簿单表汇总外接程序按钮
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsof ...
- Hadoop工程师面试题(1)--MapReduce实现单表汇总统计
数据源格式描述: 输入t1.txt源数据,数据文件分隔符"*&*",字段说明如下: 字段序号 字段英文名称 字段中文名称 字段类型 字段长度 1 TIME_ID 时间(到时 ...
- HTML的表单标签汇总
HTML的表单标签汇总 表单的元素格式: 1. 账号.密码.提交.重置 语法: <p>账号:<input type="text" name="usern ...
- SQLServer学习笔记<>.基础知识,一些基本命令,单表查询(null top用法,with ties附加属性,over开窗函数),排名函数
Sqlserver基础知识 (1)创建数据库 创建数据库有两种方式,手动创建和编写sql脚本创建,在这里我采用脚本的方式创建一个名称为TSQLFundamentals2008的数据库.脚本如下: ...
- 单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式
单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式 一 表结构如下: 万行 CREATE TABLE t_audit_operate_log ( Fid b ...
- T_SQL查询语句(一): 单表查询
############################################ 查询语句--SELECT ########################################## ...
- Python学习(三十四)—— Django之ORM之单表、联表操作
一.单表查询API汇总 <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> get(**kw ...
- 20171113xlVba指定文件夹多簿多表分表合并150
'2017年11月13日 'Next_Seven '功能:文件夹对话框指定文件夹下,合并(复制粘贴)每个Excel文件内的指定子表内容, '在名为"设置"的工作表A列 输入汇总子表 ...
- 单表扫描,MySQL索引选择不正确 并 详细解析OPTIMIZER_TRACE格式
一 表结构如下: 万行 CREATE TABLE t_audit_operate_log ( Fid bigint(16) AUTO_INCREMENT, Fcreate_time int(10 ...
随机推荐
- c#判断DatagridView表里是否有某个字段
if (DatagridView.Columns.Contains("旧ID")) { 有 ...
- P3041 [USACO12JAN]视频游戏的连击Video Game Combos
思路 简单的AC自动机上dp,暴力跳fail向子节点直接转移即可 代码 #include <cstdio> #include <algorithm> #include < ...
- swagger实战踩坑1
1.swagger error 有详细的错误信息 自己根据详细信息找问题 2.swagger error 无详细的错误信息 Controller是否重名=>重名,指定不同的 [Route(& ...
- docker 命令2
docker build -t dvm.adsplatformproxy:v1.0.0 . #build images docker run -e WWNamespace=dev -e ZKServe ...
- Codeforces 884C.Bertown Subway ----判环,思路
The construction of subway in Bertown is almost finished! The President of Berland will visit this c ...
- ECharts 使用总结
1.去掉Echarts 图标上边框和右边框 option = { title: { text: '未来一周气温变化', subtext: '纯属虚构' }, grid: { show: 'true', ...
- MyBatis数据库测试代码自动生成
<!-- generatorConfig.xml配置,其中:<plugin type="org.mybatis.generator.plugins.ToStringPlugin& ...
- 查看iis对应w3wp.exe显示的进程ID号
1.任务管理器,查看,选择列,选择PID(进程标识符) 2.通过cmd查询: 管理员身份运行cmd,跳转到C:\Windows\System32\inetsrv目录,然后运行appcmd list w ...
- mutect/mutsig/gistic官网汇总
http://software.broadinstitute.org/software/cprg/
- C#:导入Excel通用类(Xls格式)
PS:在CSV格式和XLSX格式中有写到通用调用的接口和引用的插件,所以在这个xls格式里面并没有那么详细,只是配上xls通用类. 一.引用插件NPOI.dll.NPOI.OOXML.dll.NPOI ...