Hi Guys, I am using following code to write the DATATABLE into ExcelSheet.
```
Public Shared Sub DumpExcel(ByVal dr As SqlDataReader, ByVal filename As String)
Dim tbl As New DataTable
tbl.Load(dr)
Using pck As New OfficeOpenXml.ExcelPackage()
'Create the worksheet
Dim ws As OfficeOpenXml.ExcelWorksheet = pck.Workbook.Worksheets.Add(filename)
'Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells("A1").LoadFromDataTable(tbl, True)
'Write it back to the client
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}.xlsx", filename))
HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray())
End Using
End Sub
```
But I am getting following error :
Excel found unreadable content in "xxxxxx.xlsx". Do you want to recover the contents of this workbook?
I am also attaching the EXCEL SHEET which have been generated using above code.
Thanks.
```
Public Shared Sub DumpExcel(ByVal dr As SqlDataReader, ByVal filename As String)
Dim tbl As New DataTable
tbl.Load(dr)
Using pck As New OfficeOpenXml.ExcelPackage()
'Create the worksheet
Dim ws As OfficeOpenXml.ExcelWorksheet = pck.Workbook.Worksheets.Add(filename)
'Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells("A1").LoadFromDataTable(tbl, True)
'Write it back to the client
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}.xlsx", filename))
HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray())
End Using
End Sub
```
But I am getting following error :
Excel found unreadable content in "xxxxxx.xlsx". Do you want to recover the contents of this workbook?
I am also attaching the EXCEL SHEET which have been generated using above code.
Thanks.