如何通过C#合并Excel文件 [英] How to Merge Excel files via C#
本文介绍了如何通过C#合并Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过c#开发一个应用程序,并希望合并实际谈论一件事的excel文件。我正在使用Microsoft Excel 14.0对象库打开我的Excel文件:代码如下;
I am developing an App via c#, and want to merge excel files which actually talks about one thing. I am using Microsoft Excel 14.0 Object Library to open my excel files: codes are as following;
using Excel = Microsoft.Office.Interop.Excel;
句柄事件:
handle event:
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open("D:\\**.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
但对于How Merge Excel,我没有提供任何解决方案或代码。请与我分享一些想法或代码。非常感谢。
But for How Merge Excel, I came with no solution or codes. Please share some ideas or codes with me. Thanks very much.
推荐答案
请试试这个:
Try this please:
Excel.Application xl = new Excel.ApplicationClass();
Excel.Workbook wb = xl.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorkshe et);
Excel.Worksheet ws = (Excel.Worksheet)wb.ActiveSheet;
ws.Cells[1,1] = "Testing";
Excel.Range range = ws.get_Range(ws.Cells[1,1],ws.Cells[1,2]);
range.Merge(true);
range.Interior.ColorIndex =36;
xl.Visible =true;
http://bembengarifin.wordpress.com/2010/11/02 / combine-multiple-excel-files-into-one-with-c / [ ^ ]
http ://stephenchy520.blog.com/2012/03/21/how-to-combine-excel-files-with-cvb-net/ [ ^ ]
这看起来就像你要找的而不必复制表:
http://stackoverflow.com/questions/7157677/copying-worksheets-between-workbooks-excel-interop [ ^ ]
This looks like what you are looking for without having to copy tables:
http://stackoverflow.com/questions/7157677/copying-worksheets-between-workbooks-excel-interop[^]
这篇关于如何通过C#合并Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文