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.
Comments: Hi JanKallman, First of all thank you for your help. If possible can you please provide fix for duplicate column names as it becomes critical for me. All things works perfactly,only that messagebox (i.e. found unredable content) waste my all efforts. So can you please provide a fix or any workaround to prevent this. once again thanks for your help.
```
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.
Comments: Hi JanKallman, First of all thank you for your help. If possible can you please provide fix for duplicate column names as it becomes critical for me. All things works perfactly,only that messagebox (i.e. found unredable content) waste my all efforts. So can you please provide a fix or any workaround to prevent this. once again thanks for your help.