使用Microsoft.Office.Interop.Excel而不实际拥有Excel?

时间:2022-12-10 07:36:37

I'm using Microsoft.Office.Interop.Excel in VB.Net in order to export an .xls file as a .pdf file. This was the only method I could find without relying on third party software to be installed on the running machine or using an expensive add-on to Visual Studio. This method requires opening excel and saving a file through the code.

我在VB.Net中使用Microsoft.Office.Interop.Excel,以便将.xls文件导出为.pdf文件。这是我能找到的唯一方法,而不依赖于在运行的计算机上安装第三方软件或使用昂贵的Visual Studio加载项。此方法需要打开excel并通过代码保存文件。

My problem is that I only have a trial version of Microsoft office as I never actually use it. Well the limitation of times I can open it is up as I have run the program enough times for debugging purposes and now I can't continue development on this application. Is there a development kit for visual studio that provides the API I need for this functionality without actually having Office installed? I don't need Microsoft Office so I don't want to have to buy a full version just to develop and test an application.

我的问题是我只有Microsoft Office的试用版,因为我从未真正使用它。好吧,我可以打开它的时间限制,因为我已经运行程序足够的时间用于调试目的,现在我无法继续开发此应用程序。是否有可视工作室的开发工具包,它提供了此功能所需的API而无需实际安装Office?我不需要Microsoft Office,因此我不想购买完整版本来开发和测试应用程序。

I've looked at some options like this, but there is very specific formatting that needs to remain intact in the .xls for the conversion to .pdf that doesn't seem to work if I use an intermediary format.

我已经看过这样的一些选项了,但是有非常具体的格式需要在.xls中保持完整,以便转换为.pdf,如果我使用中间格式似乎不起作用。

I've also read a little bit about the openOffice API, but is that compatible with .Net? If so, can someone point me to a tutorial that explains how to use the API with .Net? Specifically VB if possible, but I can work with C# code.

我还阅读了一些关于openOffice API的内容,但它与.Net兼容吗?如果是这样,有人可以指点我的教程,解释如何使用.Net的API?如果可能的话,特别是VB,但我可以使用C#代码。

Here is a sample of what I am trying to do, in case it helps with suggestions:

以下是我尝试做的一个示例,以防它有助于提出建议:

        Dim fileName As String = AppDomain.CurrentDomain.BaseDirectory & "LOA " & compName.Text & ".xls"
        Dim xlsApp = New Microsoft.Office.Interop.Excel.Application
        xlsApp.ScreenUpdating = False
        Dim xlsBook As Microsoft.Office.Interop.Excel.Workbook
        Dim paramExportFormat As XlFixedFormatType = XlFixedFormatType.xlTypePDF
        Dim paramExportQuality As XlFixedFormatQuality = XlFixedFormatQuality.xlQualityStandard
        Dim paramOpenAfterPublish As Boolean = False
        Dim paramIncludeDocProps As Boolean = True
        Dim paramIgnorePrintAreas As Boolean = True
        Dim paramFromPage As Object = Type.Missing
        Dim paramToPage As Object = Type.Missing
        xlsBook = xlsApp.Workbooks.Open(fileName, UpdateLinks:=False, ReadOnly:=False)
        xlsBook.ExportAsFixedFormat(paramExportFormat, AppDomain.CurrentDomain.BaseDirectory & "LOA " & compName.Text & ".pdf", paramExportQuality, paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage, paramToPage, paramOpenAfterPublish)
        xlsBook.Close(SaveChanges:=False)
        xlsApp.Quit()

4 个解决方案

#1


2  

You can install Microsoft Primary Interop Assemblies Package. You can find it here

您可以安装Microsoft Primary Interop Assemblies Package。你可以在这里找到它

But be careful. There are different packages for different office versions.

不过要小心。不同的办公室版本有不同的包。

#2


4  

Your question as stated implies a misunderstanding - the Microsoft.Office.Interop.Excel assembly contains no processing code. It is essentially a meta-data assembly that tells .NET how to talk to Excel. It is of no use when trying to do any processing without having Excel installed.

您提出的问题意味着误解--Microsoft.Office.Interop.Excel程序集不包含任何处理代码。它本质上是一个元数据程序集,告诉.NET如何与Excel通信。在没有安装Excel的情况下尝试进行任何处理时没用。

There are quite a number of free libraries that will create and manipulate Excel files - the * question you point to has some, other are on CodePlex. If you need to do calculation or rendering of the sheet with specialized formatting requirements, you're probably best off investigating the lowest-price options for getting an Excel license, or moving to a different architecture.

有很多免费的库可以创建和操作Excel文件 - 你指出的*问题有一些,其他的都在CodePlex上。如果您需要计算或呈现具有特殊格式要求的工作表,您可能最好调查获得Excel许可证或转移到其他体系结构的最低价格选项。

#3


1  

Try the tips on this thread: https://*.com/questions/769246/xls-to-pdf-conversion-inside-net -- Aspose or open office

试试这个帖子的提示:https://*.com/questions/769246/xls-to-pdf-conversion-inside-net - Aspose或open office

#4


1  

Try Codeplex. It may help you.

试试Codeplex。它可能会帮助你。

NPOI can:

NPOI可以:

  1. generate a Excel report without Microsoft Office suite installed on your server and more efficient than call Microsoft Excel ActiveX at background;
  2. 生成一个没有安装Microsoft Office套件的Excel报告,比在后台调用Microsoft Excel ActiveX更高效;
  3. extract text from Office documents to help you implement full-text indexing feature (most of time this feature is used to create search engines).
  4. 从Office文档中提取文本以帮助您实现全文索引功能(大多数时候此功能用于创建搜索引擎)。
  5. extract images from Office documents
  6. 从Office文档中提取图像
  7. generate Excel sheets that contains formulas
  8. 生成包含公式的Excel工作表

#1


2  

You can install Microsoft Primary Interop Assemblies Package. You can find it here

您可以安装Microsoft Primary Interop Assemblies Package。你可以在这里找到它

But be careful. There are different packages for different office versions.

不过要小心。不同的办公室版本有不同的包。

#2


4  

Your question as stated implies a misunderstanding - the Microsoft.Office.Interop.Excel assembly contains no processing code. It is essentially a meta-data assembly that tells .NET how to talk to Excel. It is of no use when trying to do any processing without having Excel installed.

您提出的问题意味着误解--Microsoft.Office.Interop.Excel程序集不包含任何处理代码。它本质上是一个元数据程序集,告诉.NET如何与Excel通信。在没有安装Excel的情况下尝试进行任何处理时没用。

There are quite a number of free libraries that will create and manipulate Excel files - the * question you point to has some, other are on CodePlex. If you need to do calculation or rendering of the sheet with specialized formatting requirements, you're probably best off investigating the lowest-price options for getting an Excel license, or moving to a different architecture.

有很多免费的库可以创建和操作Excel文件 - 你指出的*问题有一些,其他的都在CodePlex上。如果您需要计算或呈现具有特殊格式要求的工作表,您可能最好调查获得Excel许可证或转移到其他体系结构的最低价格选项。

#3


1  

Try the tips on this thread: https://*.com/questions/769246/xls-to-pdf-conversion-inside-net -- Aspose or open office

试试这个帖子的提示:https://*.com/questions/769246/xls-to-pdf-conversion-inside-net - Aspose或open office

#4


1  

Try Codeplex. It may help you.

试试Codeplex。它可能会帮助你。

NPOI can:

NPOI可以:

  1. generate a Excel report without Microsoft Office suite installed on your server and more efficient than call Microsoft Excel ActiveX at background;
  2. 生成一个没有安装Microsoft Office套件的Excel报告,比在后台调用Microsoft Excel ActiveX更高效;
  3. extract text from Office documents to help you implement full-text indexing feature (most of time this feature is used to create search engines).
  4. 从Office文档中提取文本以帮助您实现全文索引功能(大多数时候此功能用于创建搜索引擎)。
  5. extract images from Office documents
  6. 从Office文档中提取图像
  7. generate Excel sheets that contains formulas
  8. 生成包含公式的Excel工作表