in my web application page i have a option to export to excel . I am able to export the data to Excel but have 2 issues
1) i hav ethe option of exporting in .XLS or .XLSX format
i am able to export in .xls format from any system ie the system having office 2007 or 2003
but when i am trying to export in .XLSX format i get error
Microsoft Office Excel
---------------------------
The file you are trying to open, 'noup.xlsx', is in a different format than specified by the file extension. Verify that the file is not corrupted and that the file extension matches the file format
---------------------------
Ok
---------------------------
2) when exporting i want the excel sheet to be saved with the name thats selected from a dropdown
suppose the dropdown has text selected as CITY
i want the excel sheet as CITY.XLS/.XLSX
i my developemnet system it works fine with below code
string filename = dropdown1.SelectedItem.Text
if (Extension.SelectedValue.ToString() == ".xls")
{
Page.Response.ContentType = "application/vnd.ms-excel";
ext = ".xls";
}
else if (Extension.SelectedValue.ToString() == ".xlsx")
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
ext = ".xlsx";
}
Response.AddHeader("content-disposition", "attachment; filename=" + filename + ext);
System.IO.Stream sm = Page.Response.OutputStream;
but on production server i get the name of .aspx page