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++map用法
#include<iostream> #include<algorithm> #include<map> using namespace std; void fun ...
- git 如何revert指定范围内的commit并且只生成一个新的commit?
答:一共分成两步 一. revert多个commit并生成多个新的commit git revert <old commit>^..<new commit> 二. 使用reba ...
- gerrit的使用笔记
1.clone的时候一定要同时选择上clone with commit-msg hook和ssh,这样才能使用change id,同时使用ssh push到remote. 2.如果是使用了clone ...
- SpringBoot Mybatis问题收集
1.在SpringBoot中打印mybatis中执行的sql 其实在application.properties 文件下,添加一下配置即可: logging.level.org.springframe ...
- 【做题】arc072_f-Dam——维护下凸包
题意:有一个容量为\(L\)的水库,每天晚上可以放任意体积的水.每天早上会有一定温度和体积的水流入水库,且要保证流入水之后水的总体积不能超过\(L\).令体积分别为\(V_1,V_2\),温度分别为\ ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...
- Docker 开发最佳实践
Docker development best practices The following development patterns have proven to be helpful for p ...
- js字符串与十六进制相互转换
1.字符串(汉字)转换为十六进制 主要使用字符串.charCodeAt()方法,此方法返回一个字符的Unicode值,再用toString(16)方法,该方法是先将数字对象转换为二进制,再把二进制转化 ...
- SyncDictionary
using System; using System.Collections; using System.Collections.Generic; using System.Threading; us ...
- 【Python】【网络编程】
#[[网络编程]] # 网络通信就是两个进程之间在通信 # [TCP/IP]'''TCP/IP简介 阅读: 125242虽然大家现在对互联网很熟悉,但是计算机网络的出现比互联网要早很多. 计算机为了联 ...