[英]Unable to open Excel when i run build (vstest) in azure devops pipeline
I am using Microsoft.Office.Interop.Excel to open the excel workbook to do some automation for a given project. 我正在使用Microsoft.Office.Interop.Excel打开excel工作簿以对给定项目进行一些自动化。 When i run my build, i encountered this error
当我运行我的构建时,我遇到此错误
System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). System.Runtime.InteropServices.COMException:检索具有以下错误的CLSID为{00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80040154未注册类(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG))。
Which comes from this code in my visual studios. 这来自我的视觉工作室中的这段代码。 excel.Application x1app = new excel.Application();
excel.Application x1app =新的excel.Application();
I am able to run the test locally but when i run it in azure devops, it dosen't work. 我可以在本地运行测试,但是当我在天蓝色的devops中运行它时,它将无法正常工作。 I believe it is because devops does not have excel inside thus unable to execute the code.
我相信这是因为devops内部没有excel,因此无法执行代码。
Are there any alternatives i can try besides EPPlus. 除了EPPlus,我还有其他选择吗?
excel.Application x1app = new excel.Application(); x1app.SheetsInNewWorkbook = 1; x1app.Visible = true; excel.Workbook x1workbook = x1app.Workbooks.Open(); excel.Workbook NewWorkBook = x1app.Workbooks.Add(); for (sheets) { excel._Worksheet x1worksheet = x1workbook.Sheets[x]; x1worksheet.Copy(Type.Missing, After: NewWorkBook.Sheets[x - 3]); } Thread.Sleep(2000);
I should be able to run the build successfully on devops 我应该能够在devops上成功运行构建
According to your description, what you are doing required Excel installed on the build agent. 根据您的描述,您正在执行的操作需要在生成代理上安装Excel。
If you are using host build agent in Azure DevOps. 如果要在Azure DevOps中使用主机生成代理。 It seems not be installed on the machines.
好像没有安装在机器上。 You could find a full list of software which is installed on machines in the Azure Pipelines Hosted agent pool such as this Azure Pipelines Hosted VS2017 image .
您可以找到在Azure Pipelines Hosted代理池中的计算机上安装的软件的完整列表,例如此Azure Pipelines Hosted VS2017映像 。
As a workaround, if Microsoft-hosted agents don't meet your needs, then you can deploy your own self-hosted agents . 解决方法是,如果Microsoft托管的代理不能满足您的需求,那么您可以部署自己的自托管代理 。
Just need to make sure your self host agent environment is the same as your local development environment. 只需确保您的自托管代理环境与本地开发环境相同即可。
Besides, not totally clearly about your detail useage of excel. 此外,您对Excel的详细用法还不太清楚。 You could also try to use openxml.
您也可以尝试使用openxml。 Please take a look at this similar question here: How can I build a project containing Excel creation in VSTS?
请在这里查看类似的问题: 如何在VSTS中构建包含Excel创建的项目?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.