views:

341

answers:

2
+1  Q: 

Render Excel File

Hi,

I am actually rendering an excel file in the browser. I use the Response.Writefile(filePath) to dod this. It is working perfectly fine in few of the machines. I am getting a pop up with "Open","Save" and "Cancel" option.

But incase of few machines after i do a save click on the popup a plain empty page remains open. This happens only in few of the machines. This window just flickers in the other machine and closes by itself. Please let me know of what can be done to avoid this plain empty page to be closed by itself after the file is opened or saved.

+1  A: 

Are you setting any HTTP headers? If you are not, you are relying on the browser to interpret the data correctly.

To tell the browser you are sending excel content:

Response.ContentType = "application/x-excel";

To tell the browser to treat the response as download:

Response.AddHeader("content-disposition", "inline; filename=\"" + YourSuggestedFileName + "\"");

The machines giving you trouble likely don't know what to do with the excel data.

HectorMac
This worked out fine. but i still have a problem. When this is opening in a seperate explorer page, i need to get the option to save the file as file.xls File. But when i login into application i disable the Menu bar.Is there anyway i can enable it only for this single page?
Vinodtiru
A: 

The problem with this approach is that date fields and number fields are all rendered as a string. The end user has to then explicitly modify the type for these fields if they want to sort them.

If you have the budget, I suggest using a component like: Aspose.Cells