0

Hi All,

I am trying to output an excel workbook that I created else where in the program through a Response.Write() call.

The issue I am having is that when I call the Response.Write(); it shows the download dialog for the excel file which it is supposed, but when opened, it opens two docs, the excel file, and then another page doc, which has Microsoft.Interop.Excel.Workbook in cell one.

And to add to the fun, the incorrect excel doc is visible, where as the correct one is hidden until the incorrect file is closed. At which point the correct file shows up exactly where the incorrect one just was. Below is the code I am using.

Excel.Workbook exWB = rm.GenerateNewEnrollmentReport(students);

            Response.Clear();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=Report.xls");
            Response.Write(exWB);
            Response.End();

If anyone has any thoughts, I would be glad to hear them!

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by croker10
0

Never mind, I figured it out. Response.Write(exWB); does not work for excel workbooks. It was really doing Response.Write(exWB.toString()), and since I was returning the excel workbook, the code was not doing WorkBook.Close() and Application.Quit(), without which, the formatted report was being left open in the background.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.