• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 653
  • Last Modified:

Save to Excel not working on IIS

I have a button on ASP.Net page that saves data in a session to an Excel file. I have used microsoft excel dll's and it works fine in visual web developer. But as soon as I put the code on IIS it does not work. I dont get ant errors I click on the button and nothing happens.

Here is the code......
DateTime dt = System.DateTime.Now;
        int currentMonth = dt.Month - 1;
        int currentYear = dt.Year;

        Microsoft.Office.Interop.Excel.Application application;
        Microsoft.Office.Interop.Excel.Workbook book;
        Microsoft.Office.Interop.Excel.Worksheet sheet;

        application = new Microsoft.Office.Interop.Excel.ApplicationClass();
        book = application.Workbooks.Add(Type.Missing);
        application.Visible = true;

        sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Worksheets[1];
        sheet.Name = "Forecast";

        // Header

        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 1]).Value2 = "Distributor";
        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 2]).Value2 = "Customer";
        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 3]).Value2 = "End Customer";
        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 4]).Value2 = "Project";
        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 5]).Value2 = "Territory";
        ((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 6]).Value2 = "Product";
0
apparition
Asked:
apparition
  • 2
1 Solution
 
dstanley9Commented:
Is excel installed on the server?  The same version that you are developing against?
0
 
apparitionAuthor Commented:
I am doing the development on my server. Excel is set up and so is Visual Web developer. It runs fine from VWD but when I copy it over to IIS wwwroot directory and try to run it from there it does not work
0
 
apparitionAuthor Commented:
I guess no one wants to help....I ended up just generating a CSV file
0
 
Gruff82Commented:
Hi,

I wouldn't use excel automation on the server due to instability issues. However all is not lost

What I would recommend though is using the excellent Koogra Excel BIFF library from sourceforge (http://sourceforge.net/projects/koogra/) and opening your workbook using that. The library reads and writes in the BIFF8 format which is the file format for Excel 97 and on.

Using this library you wont need to use excel or any of the interop librarys... performance is good and its easy to use...

the object model is very simialir to the excel object model and doesn't take very long to get it up and running with it.

Just thought I'd let you know even though you've already done it with a csv.

Thanks

gareth
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now