简体   繁体   English

当我在Azure Devops管道中运行构建(vstest)时无法打开Excel

[英]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,因此无法执行代码。

  1. Is there any way i can solve this error while still using interop? 有什么办法可以在仍然使用互操作的同时解决此错误?
  2. 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.

相关问题 运行 Azure DevOps 构建管道时自定义文化不适用 - Custom Culture not applying when running an Azure DevOps build pipeline 无法在 Azure Devops 中打开附加到工作项的 Excel 文件 - Unable to open the Excel file attached to work item in Azure Devops 如何从代码运行 Azure DevOps 管道? - How to run an Azure DevOps pipeline from code? 无法运行 EdgeDriver 自动化测试:Azure DevOps 的 VsTest VM 在默认安装位置没有 Edge 二进制文件? - Can't run EdgeDriver automated tests: Azure DevOps' VsTest VM has no Edge binary in default install location? Azure DevOps Pipeline 变量定义在构建前自动更改 - Azure DevOps Pipeline variables define automatically change before build 在 Azure Devops Pipeline 中使用 MSBuild 构建和发布 MVC4 应用程序 - Build and Publish MVC4 application using MSBuild in Azure Devops Pipeline azure devops 管道构建失败,出现错误 CS1043 - azure devops pipeline build fails on error CS1043 在 Azure DevOps Build Pipeline 中恢复 Libman JS 库 - Restore Libman JS Libraries in Azure DevOps Build Pipeline Docker 映像构建在 Azure DevOps 发布管道中失败 - Docker image build fails in Azure DevOps release pipeline 是否可以在 azure devops 管道中动态构建 select 程序集? - Is it possible to dynamically select assemblies to build in azure devops pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM