当前位置:   article > 正文

C#调用WPS的etapi.dll读写Excel_c# wpsapi.dll

c# wpsapi.dll

开发环境要求

  1. 安装WPS Office专业版,2016或者2019都可以

  2. 推荐下载地址: https://www.jb51.net/softs/681559.html

  3. 在项目中引用etapi.dll

  4. DLL在WPS的安装目录中,如C:\Program Files (x86)\Kingsoft\WPS Office\10.8.2.6666\office6

代码开发

代码的写法与使用Microsoft.Office.Interop.Excel.dll的方法完全一致

  • 注:客户端安装Office/WPS都可以正常使用程序,WPS安装个人版即可

示例:C#

  1. Excel.Application app;
  2. Excel.Workbook book;
  3. Excel.Worksheet sheet;
  4. Excel.Worksheet sheet2;
  5. Excel.Range range;
  6. app = new Excel.Application();
  7. book = app.Workbooks.Add();
  8. range = sheet.Range("A1");
  9. range.Value2 = "Hello:";
  10. sheet.SheetName = "我是Sheet1";
  11. book.SaveAs("my file path");
  12. book.Close();
  13. app.Quit();
  14. System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
  15. GC.Collect(); // 强制进行垃圾回收

示例:VB.net

  1. Dim app As Excel.Application
  2. Dim book As Excel.Workbook
  3. Dim sheet As Excel.Worksheet
  4. Dim sheet2 As Excel.Worksheet
  5. Dim range As Excel.Range
  6. app = New Excel.Application
  7. book = app.Workbooks.Add()
  8. range = sheet.Range("A1")
  9. range.Value2 = "Hello:"
  10. sheet.SheetName = "我是Sheet1";
  11. book.SaveAs("my file path")
  12. book.Close()
  13. app.Quit()
  14. System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
  15. GC.Collect() '强制进行垃圾回收

以上为WPS使用方法,不过我建议大家使用Spire.Xls来创建/读写Excel

可参照我的另一篇文章:C#使用Free Spire.XLS创建Excel

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/199824
推荐阅读
相关标签
  

闽ICP备14008679号