5

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()
Community
  • 1
  • 1
MaQleod
  • 1,011
  • 6
  • 22
  • 33

4 Answers4

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.

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.

Govert
  • 16,387
  • 4
  • 60
  • 70
  • I understand that it just points to excel. I understand that there are other libraries that automate the process differently or that don't require excel at all, but the ones suggested thus far cost money or require different formats. I require using .NET and I require only using .xls and .pdf formats. I need something that does not need excel, or that can stand in place of excel, that does not cost money or require installation on client machine and has no intermediary format change. The article offers no such solution (something like SpreadsheetGear or Aspose but free would be ideal). – MaQleod May 04 '11 at 14:17
  • This one also looks good for what you need (though not free): http://www.sautinsoft.com/convert-excel-xls-to-pdf/spreadsheet-xls-excel-to-pdf-export-component-asp.net.php. – Govert May 04 '11 at 15:29
  • I had looked at that one, and yes, it is what I need as far as functionality goes, but there is no way I'd get authorization for software that costs money. I'm stuck looking for a free option. – MaQleod May 04 '11 at 16:20
1

Try Codeplex. It may help you.

NPOI can:

  1. generate a Excel report without Microsoft Office suite installed on your server and more efficient than call Microsoft Excel ActiveX at background;
  2. extract text from Office documents to help you implement full-text indexing feature (most of time this feature is used to create search engines).
  3. extract images from Office documents
  4. generate Excel sheets that contains formulas
Grerk
  • 11
  • 1
1

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

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

e-mre
  • 3,305
  • 3
  • 30
  • 46
  • 3
    He asked for a package that didn't require Excel to be installed. The first thing you get when you download the PIA and run the installer is a message saying you need to install Office first. – Mark Smith Jul 11 '12 at 13:52
  • PIA does that exactly. When you install PIA you can do stuff even if you don't have office installed. I am using this solution for my project for the last 3 years. – e-mre Aug 15 '12 at 11:39
  • 2
    @MarkSmith is exactly right. I tried this on our test server which does not have Office installed, and it told me the same thing; you need Office. – Chiramisu Sep 27 '12 at 22:31
0

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

Community
  • 1
  • 1
ariel
  • 15,620
  • 12
  • 61
  • 73
  • I already ruled out options that require other installations on client machine (openoffice) or that are expensive (aspose). That was clearly stated in the first paragraph of my question. – MaQleod May 04 '11 at 04:16