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 ...
随机推荐
- How to Rerun Failed Tests in JUnit?
该帖转自其他出处 Sometimes due to some temporarily problems such as connection problems, server problems, br ...
- CentOS7搭建jdk
背景 现在很多Linux系统在安装完成时就自带jdk,但是系统自带的jdk有时候并不符合我们的需求,这时候我们需要自己来安装jdk. 步骤 下载jdk,我下载的是64位的jdk-8u161-linux ...
- Bootstrap3基础 nav 便签页(横版、竖版)
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- 【特性】Redis4.0新特性
模块系统 Redis 4.0 发生的最大变化就是加入了模块系统, 这个系统可以让用户通过自己编写的代码来扩展和实现 Redis 本身并不具备的功能, 具体使用方法可以参考 antirez 的博文< ...
- UVA11270 Tiling Dominoes(轮廓线动态规划)
轮廓线动态规划是一种基于状态压缩解决和连通性相关的问题的动态规划方法 这道题是轮廓线动态规划的模板 讲解可以看lrj的蓝书 代码 #include <cstdio> #include &l ...
- (转)干货|这篇TensorFlow实例教程文章告诉你GANs为何引爆机器学习?(附源码)
干货|这篇TensorFlow实例教程文章告诉你GANs为何引爆机器学习?(附源码) 该博客来源自:https://mp.weixin.qq.com/s?__biz=MzA4NzE1NzYyMw==& ...
- (转载)Rime输入法—鼠须管(Squirrel)词库添加及配置
为什么用Rime 13年底的时候,日本爆出百度的日本版本输入法的问题,要求政府人员停用,没当回事,反正我没用,当然了,有关搜狗和用户隐私有关的问题就一直没有中断过,也没太在意.但,前几天McAfee爆 ...
- facebook api call——error
Error Codes send-api error-codes whatsapp api errors marketing-api error-reference graph-api/using-g ...
- FZU 2150 Fire Game(点火游戏)
FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description - 题目描述 ...
- SAP FI 常用表
SAP FI 常用表 GL 部分: FAGLFLEXT 新总账汇总表 GLT0 旧总帐汇总表 SKA1 总账科目主记录 (科目表) 科目表层数据 SKAT 总帐科目主记录(科目表:说明) 包括语言代码 ...