how to deploy excel app to server without MS office

I have written a windows service in vb.net to create Excel reports (lot of formatting, calculations ect.,)
The program works file in my PC but not in a server. My PC had been installed Excel 2003, but the server has no any MS Office.

To install my application in the server I generated a setup.exe and msi file and copied them to a folder in the server, and run setup.exe. After running the setup I saw that three dll were added in that folder:

Microsoft.Office.Interop.Excel.dll, Microsoft.Vbe.Interop.Excel.dll, and Office.dll.

Those three dlls should contain all the functions that are necessary for reading data from Excel file. However, the error was generated as soon as the code reaches the following three lines:

Dim myExcel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet

The error message reads

Unhandled Exceptionj: System.Runtime.InteropServices.COMException <Ox80040154>: Retrieving the COM Class factory for Component with CLSID <&> failed due to the following error: 80040154.

Any help would be greatly appreciated.
jyothsna1803Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChloesDadCommented:
I had this problem as well, and the simple answer is that you can't.

If you want to run this code on the server then you have to purchase a copy of excel for the server. Microsoft wouldn't allow you to freely distribute Excel, as its their copywrite etc.
jyothsna1803Author Commented:
ChloesDad, Thanks for your quick response. Does it mean Microsoft is charing extra bucks for interopServices for each server? how funny it is..If you have any other workble solutions please advice me..
ChloesDadCommented:
The interop services allow you to access the objects in vb, but you need to have the actual program to run code.

We changed our code to write out a comma separated file that can be imported into excel, but this only allows text not formulae to be included in the file
jyothsna1803Author Commented:
Without using excel object i have coded and seems it is working fine, But i don't have any formatting options in my style.

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Public Class ExcelWriter
    Private stream As Stream
    Private writer As BinaryWriter

    Private clBegin As UShort() = {&H809, 8, 0, &H10, 0, 0}
    Private clEnd As UShort() = {&HA, 0}


    Private Sub WriteUshortArray(ByVal value As UShort())
        For i As Integer = 0 To value.Length - 1
            writer.Write(value(i))
        Next
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the <see cref="ExcelWriter"/> class.
    ''' </summary>
    ''' <param name="stream">The stream.</param>
    Public Sub New(ByVal stream As Stream)
        Me.stream = stream
        writer = New BinaryWriter(stream)
    End Sub

    ''' <summary>
    ''' Writes the text cell value.
    ''' </summary>
    ''' <param name="rownum">The row.</param>
    ''' <param name="col">The col.</param>
    ''' <param name="value">The string value.</param>
    Public Sub WriteCell(ByRef rownum As Integer, ByVal col As Integer, ByVal value As String)
        Dim clData As UShort() = {&H204, 0, 0, 0, 0, 0}
        Dim iLen As Integer = value.Length
        Dim plainText As Byte() = Encoding.ASCII.GetBytes(value)
        clData(1) = CUShort((8 + iLen))
        clData(2) = CUShort(rownum)
        clData(3) = CUShort(col)
        clData(5) = CUShort(iLen)
        WriteUshortArray(clData)
        writer.Write(plainText)

    End Sub

    ''' <summary>
    ''' Writes the integer cell value.
    ''' </summary>
    ''' <param name="row">The row number.</param>
    ''' <param name="col">The column number.</param>
    ''' <param name="value">The value.</param>
    Public Sub WriteCell(ByVal row As Integer, ByVal col As Integer, ByVal value As Integer)
        Dim clData As UShort() = {&H27E, 10, 0, 0, 0}
        clData(2) = CUShort(row)
        clData(3) = CUShort(col)
        WriteUshortArray(clData)
        Dim iValue As Integer = (value << 2) Or 2
        writer.Write(iValue)
    End Sub

    ''' <summary>
    ''' Writes the double cell value.
    ''' </summary>
    ''' <param name="row">The row number.</param>
    ''' <param name="col">The column number.</param>
    ''' <param name="value">The value.</param>
    Public Sub WriteCell(ByVal row As Integer, ByVal col As Integer, ByVal value As Double)
        Dim clData As UShort() = {&H203, 14, 0, 0, 0}
        clData(2) = CUShort(row)
        clData(3) = CUShort(col)
        WriteUshortArray(clData)
        writer.Write(value)

    End Sub

    ''' <summary>
    ''' Writes the empty cell.
    ''' </summary>
    ''' <param name="row">The row number.</param>
    ''' <param name="col">The column number.</param>
    Public Sub WriteCell(ByVal row As Integer, ByVal col As Integer)
        Dim clData As UShort() = {&H201, 6, 0, 0, &H17}
        clData(2) = CUShort(row)
        clData(3) = CUShort(col)
        WriteUshortArray(clData)
    End Sub

    ''' <summary>
    ''' Must be called once for creating XLS file header
    ''' </summary>
    Public Sub BeginWrite()
        WriteUshortArray(clBegin)
    End Sub

    ''' <summary>
    ''' Ends the writing operation, but do not close the stream
    ''' </summary>
    Public Sub EndWrite()
        WriteUshortArray(clEnd)
        writer.Flush()
    End Sub
End Class

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.