Excel found unreadable content in '[filename].xlsx

Hey Guys i am getting an error mentioned above when i do the following

Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet = excel.Worksheets[0];
Aspose.Cells.Cells cells = sheet.Cells;

if (ds.Tables[1].Rows.Count > 0)
cells.ImportDataTable(ds.Tables[1], true, "A1");

for (int j = 0; j < ds.Tables[1].Columns.Count; j++)
{
sheet.AutoFitColumn(j);
sheet.Cells[0, j].Style.Font.IsBold = true;
}

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "MergedDocument.xlsx");
System.IO.MemoryStream stream = new System.IO.MemoryStream();
excel.Save(stream, FileFormatType.Excel2007Xlsx);
Response.BinaryWrite(stream.ToArray());

I am using 4.4.0.5


This message was posted using Aspose.Live 2 Forum

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please use the following line of code at the end of your code.

Response.End();

Please see the following updated code:

Aspose.Cells.Workbook excel = new Aspose.Cells.Workbook();

Aspose.Cells.Worksheet sheet = excel.Worksheets[0];

Aspose.Cells.Cells cells = sheet.Cells;

if (ds.Tables[1].Rows.Count > 0)

cells.ImportDataTable(ds.Tables[1], true, "A1");

for (int j = 0; j < ds.Tables[1].Columns.Count; j++)

{

sheet.AutoFitColumn(j);

sheet.Cells[0, j].Style.Font.IsBold = true;

}

Response.Clear();

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Disposition", "attachment; filename=" + "MergedDocument.xlsx");

System.IO.MemoryStream stream = new System.IO.MemoryStream();

excel.Save(stream, FileFormatType.Excel2007Xlsx);

Response.BinaryWrite(stream.ToArray());

Response.End();

Thank You & Best Regards,

Thanks, That worked for me.