赞
踩
安装WPS Office专业版,2016或者2019都可以
在项目中引用etapi.dll
DLL在WPS的安装目录中,如C:\Program Files (x86)\Kingsoft\WPS Office\10.8.2.6666\office6
代码的写法与使用Microsoft.Office.Interop.Excel.dll的方法完全一致
示例:C#
- Excel.Application app;
- Excel.Workbook book;
- Excel.Worksheet sheet;
- Excel.Worksheet sheet2;
- Excel.Range range;
-
- app = new Excel.Application();
- book = app.Workbooks.Add();
- range = sheet.Range("A1");
- range.Value2 = "Hello:";
- sheet.SheetName = "我是Sheet1";
- book.SaveAs("my file path");
- book.Close();
- app.Quit();
- System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
- GC.Collect(); // 强制进行垃圾回收
示例:VB.net
- Dim app As Excel.Application
- Dim book As Excel.Workbook
- Dim sheet As Excel.Worksheet
- Dim sheet2 As Excel.Worksheet
- Dim range As Excel.Range
-
- app = New Excel.Application
- book = app.Workbooks.Add()
- range = sheet.Range("A1")
- range.Value2 = "Hello:"
- sheet.SheetName = "我是Sheet1";
- book.SaveAs("my file path")
- book.Close()
- app.Quit()
- System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
- GC.Collect() '强制进行垃圾回收
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。