[英]Is NPOI better than Office Interop in C# for automation using Selenium WebDriver
I am using C# and Selenium WebDriver for automating our web application. 我正在使用C#和Selenium WebDriver来自动化我们的Web应用程序。 The test data will be read from Excel sheets(.xlsx).
测试数据将从Excel工作表(.xlsx)中读取。 Being new to C#, I want to know if using NPOI is a good option to read/write data from Excel or using Interop in C# is a preferred.
作为C#的新手,我想知道使用NPOI是从Excel读取/写入数据的好选择还是在C#中使用Interop是首选。 I personally prefer NPOI as I feel it is easier to use.
我个人更喜欢NPOI,因为我觉得它更容易使用。 This could be because of my exposure to Apache POI when I used Java and Selenium for automation.
这可能是因为我在使用Java和Selenium进行自动化时接触过Apache POI。 Kindly help.
请帮助。
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)中的Microsoft Office应用程序自动化,因为Office可能表现出不稳定的行为和/在此环境中运行Office时出现死锁或死锁。
https://support.microsoft.com/en-us/kb/257757 https://support.microsoft.com/zh-CN/kb/257757
Don't use Office Interop in web environments. 不要在网络环境中使用Office Interop。
At first, as mentioned already, Interop requires actual Excel application to be installed on server, which is not always a good idea ar may even be not possible at all (ie if you are yousing Azure Web Apps). 首先,如前所述,Interop需要在服务器上安装实际的Excel应用程序,这并不是一个好主意,甚至根本不可能(例如,如果您正在使用Azure Web Apps)。 I'm currently working on a project which we have rewritten using Interop, but now are going to migrate to NPOI mainly because of it's speed: some tasks require around 5-8 seconds using Excel Interop, because it actually launches full Excel app and communicates with it via RPC.
我目前正在处理一个项目,该项目已使用Interop进行了重写,但现在由于其速度原因,现在将迁移到NPOI:使用Excel Interop某些任务大约需要5-8秒,因为它实际上会启动完整的Excel应用程序并进行通信通过RPC使用它。 NPOI works directly with Excel files and today while testing one heave action was performed in just around 300 milliseconds including saving modified workbook to new file.
NPOI直接与Excel文件一起使用,今天,在测试一个举升动作的过程中,大约300毫秒就执行了一次,包括将修改后的工作簿保存到新文件中。 So if you have to work specifically with old binary .xls files NPOI is good choise.
因此,如果您必须专门使用旧的二进制.xls文件,则NPOI是不错的选择。 If you are going to work with modern OpenXML files (.xlsx), take a look at https://github.com/closedxml/closedxml
如果您要使用现代OpenXML文件(.xlsx),请查看https://github.com/closedxml/closedxml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.