Solved

how to deploy excel app to server without MS office

Posted on 2009-05-11
4
789 Views
Last Modified: 2012-06-22
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.
0
Comment
Question by:jyothsna1803
  • 2
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 200 total points
ID: 24359286
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.
0
 

Author Comment

by:jyothsna1803
ID: 24364384
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..
0
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 200 total points
ID: 24365852
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
0
 

Accepted Solution

by:
jyothsna1803 earned 0 total points
ID: 24981045
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now