Reputation: 2659
I am using EPPlus library for creating excel file. here is the code that I am using
public static byte[] CreateExcelFile(DataTable dataTable)
{
using (ExcelPackage pck = new ExcelPackage())
{
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Sheet1");
//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(dataTable, true);
//Format the header for column A1:AZ1
using (ExcelRange rng = ws.Cells["A1:AZ1"])
{
rng.Style.Font.Bold = true;
}
////Example how to Format Column 1 as numeric
//using (ExcelRange col = ws.Cells[2, 1, 2 + dataTable.Rows.Count, 1])
//{
// col.Style.Numberformat.Format = "#,##0.00";
// col.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
//}
return pck.GetAsByteArray();
}
}
Then I am generating a resposne with this content type : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
the file is being downloaed but with unknown type. If you rename the file to a.xlsx it will open the excel file.
I was using an old version then I updated the dll with the latest one but the issue is still there. Any ideas ?
Upvotes: 0
Views: 1059
Reputation: 9979
Change Content-Type to "application/octet-stream" and add Content-Disposition with value "attachment; filename=foo.xlsx" to you respons headers.
Upvotes: 1