使用Microsoft.Office.Interop.Excel而不实际有Excel? [英] Using Microsoft.Office.Interop.Excel without actually having Excel?

查看:199
本文介绍了使用Microsoft.Office.Interop.Excel而不实际有Excel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

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.

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

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.

下面是我正在尝试做的一个例子,以防它有助于建议:

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()


推荐答案

您可以安装Microsoft Primary Interop Assemblies Package。你可以找到它 here

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

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

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

这篇关于使用Microsoft.Office.Interop.Excel而不实际有Excel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆