OLE Automation (C#读取EXCEL)

            object missing =System.Reflection.Missing.Value;

            ApplicationClass app = newApplicationClass();           

            app.SheetsInNewWorkbook = 1;

            app.Visible = true;

            Workbook wb =app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

            Worksheet sheet =(Worksheet)wb.Sheets[1];

            sheet.get_Range("A1","A1").Value2 = "hello";

            wb.SaveAs("c:/1.xls",XlFileFormat.xlExcel9795, missing, missing, missing, missing,XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);

            app.Quit();

 

OLE Automation:程序启动一个Excel进程,然后和Excel进程进行通讯来进行Excel的操作。优点:强大,能够使用Excel的所有功能,要求装Excel,微软最推荐这种用法,因为可以促进Excel的销量。会启动Excel进程,不适合于服务器(比如Asp.Net网站,安全性、效率)。

 

推荐:NPOI操作Excel

相关文章
相关标签/搜索