开发环境要求
-
安装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的方法完全一致
- 注:客户端安装Office/WPS都可以正常使用程序,WPS安装个人版即可
示例: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() '强制进行垃圾回收