在c#中的Excel格式表格

我想通过我的c#应用程序来生成excel表格,按照模板的excel /源excel表格。

我已经完成了使用Linq to XML和将Excel工作簿保存为XML时使用的SpreadsheetML格式。 基本上,你创build的格式电子表格,但你需要它。 然后,将其保存为XML。 您可以find想要以编程方式更改的区域,并使用Linq to XML来执行此操作。 在电子表格中识别感兴趣区域的最简单方法是使用带标签的单元格。

SpreadsheetML可能会变得非常复杂,但是这种方法在过去对我来说很合适。

使用Interop.Excel程序集 ( 如何 ),您可以在创build新的工作簿时加载您的Excel模板:

Microsoft.Office.Interop.Excel.Application xlApp = new Application(); Microsoft.Office.Interop.Excel.Workbook wb = xlApp.Workbooks.Open("excelTemplateFile.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);