Hello,
I am using Aspose.Cells to export a datatable to xlsx format, this process is done by creating the workbook, converting it to bytes, and then opening it in a web response. This is my code:
Workbook wbk = new Workbook(FileFormatType.Xlsx);
wbk.Worksheets.RemoveAt(“Sheet1”);
foreach (DataTable dataTable in dataSet.Tables)
{
Worksheet wks = wbk.Worksheets.Add(dataTable.TableName);
ExcelWorkbookHelper.AddWorkSheetDataAspose(dataTable, wks);
}
byte[] array;
MemoryStream ms = new MemoryStream();
ms = wbk.SaveToStream();
array = ms.ToArray();
return array;
then:
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = false;
Response.AppendHeader(“Content-Type”, “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”);
string filename = string.Format("{0}.{1}", “CodeComparison-” + txtCode.Text, “xlsx”);
Response.AppendHeader(“Content-Disposition”, “attachment; filename=”" + filename + “”");
Response.AppendHeader(“Content-Length”, excelBytes.Length.ToString());
Response.Flush();
Response.OutputStream.Write(excelBytes, 0, excelBytes.Length);
Response.Flush();
Response.Close();
this is giving me an error when opening the file that the file format or extension is not valid, if I change the file extension into xls, it will open normally
Hi,
that worked fine
Thank you
Hi,