Archive for 22 4 月, 2009

C#生成Excel文件的方法

星期三, 22 4 月, 2009

1. 首先添加Excel的Reference到项目中
右击项目的References,选“Add Reference...”菜单,在COM组里选择“Microsoft Excel 11.0 Object Labrary”(安装的Excel版本不一样这里的版本可能会有变化,我这里是Excel 2003)

2. 新建excel文件实例代码
Microsoft.Office.Interop.Excel.Application app = null;
Microsoft.Office.Interop.Excel.Workbook workbook = null;
Microsoft.Office.Interop.Excel.Worksheet sheet = null;
object missing = System.Reflection.Missing.Value;
try
(更多…)