|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Excel.Worksheet newWorksheet;
- newWorksheet = (Excel.Worksheet)app.Worksheets.Add();
- newWorksheet.Name = "外部Excel合并";
- //------------------------------------------------------
- OpenFileDialog dlg = new OpenFileDialog();
- dlg.Multiselect = true;//等于true表示可以选择多文件
- dlg.Title = "请选择文件";
- dlg.Filter = "Excel文件|*.xls;*.xlsx";
- if (dlg.ShowDialog() == DialogResult.OK)
- {
- foreach (string file in dlg.FileNames)
- {
- int qrows = app.Worksheets["外部Excel合并"].UsedRange.Rows.Count;
- Excel.Application merapp = new Excel.Application();
- merapp.Visible = false;//设定合并过程是否可视化
- Excel.Workbook merwbk = merapp.Workbooks.Open(file);
- if (merwbk.Worksheets.Count > 0)
- {
- Excel.Worksheet Worksheet = merwbk.Worksheets[1];
- Excel.Range range = Worksheet.get_Range(Worksheet.UsedRange.Address.ToString());//获取数据区域
- range.Copy(newWorksheet.Range["A" + (qrows + 1), System.Type.Missing]);
- }
- }
- }
复制代码 麻烦帮忙看看是那错了啊第一次搞VSTO不懂。。。!
|
|