Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Microsoft.Office.Interop.Excel without actually having Excel?

Tags:

excel

vb.net

pdf

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.

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.

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.

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()
like image 707
MaQleod Avatar asked May 01 '11 01:05

MaQleod


People also ask

Does Microsoft Office Interop Excel require Excel to be installed?

Some issues when using Microsoft Office Interop (Excel Automation) from C# or VB.NET are: It requires a license for Microsoft Office on every client machine. It requires all client machines to have the same version of Microsoft Excel installed.

Do you need Office installed to use Interop?

You cannot use the Interop libraries without Office installed. This is a requirement from Microsoft, so even if you figured out how to do it you would be violating the EULA. There are alternatives (Aspose, OOXML SDK, etc.) that might be useful but to use Interop on the server, you need to install Office.

How do you use Excel without install?

Opening Excel Documents Using Apache Office It's a free program and it's compatible with Excel files, so you can use it to open your files without Excel. If you don't have it already, make sure you download Apache Office. You can do that here https://www.openoffice.org/download/. Once you've installed it, open the app.


1 Answers

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.

There are quite a number of free libraries that will create and manipulate Excel files - the Stackoverflow 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.

like image 69
Govert Avatar answered Sep 22 '22 06:09

Govert