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

16,451

Solution 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.

Solution 2

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.

Solution 3

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
Share:
16,451
MaQleod
Author by

MaQleod

I'm a Software Quality Principal Engineer that specializes in Networking and hardware (with a strong emphasis on Unix/Linux systems). My background is in Telecom and Network troubleshooting. I am proficient in both Ethernet and Infiniband standards. I code primarily with Python, Autoit, C and and SQL in my spare time, but I like to occasionally tinker in other languages. My degree is in Classical Numismatics and Archaeology. I also keep a blog on investing. profile for MaQleod on Stack Exchange, a network of free, community-driven Q&A sites http://stackexchange.com/users/flair/343e8ac1ebe84dacb26151af03317dcd.png

Updated on June 18, 2022

Comments

  • MaQleod
    MaQleod almost 2 years

    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()
    
  • MaQleod
    MaQleod almost 13 years
    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
    MaQleod almost 13 years
    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).
  • Govert
    Govert almost 13 years
    This one also looks good for what you need (though not free): sautinsoft.com/convert-excel-xls-to-pdf/….
  • MaQleod
    MaQleod almost 13 years
    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.
  • Mark Smith
    Mark Smith over 11 years
    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.
  • e-mre
    e-mre over 11 years
    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.
  • Chiramisu
    Chiramisu over 11 years
    @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.