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!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.