Greeting All
I am trying to export Data table into excel using ClosedXML and the file which gets downloaded has the data from the table but if I try to upload it on another system it does not read.
In order for the other system to read I have to open the file double click on any (even empty) cell and save it. Once it is saved again I am able to upload that file without issue.
Another thing I have notices when the file is downloaded it is 10KB and after saving again (without adding anything) its size increases to 11KB.
I have tired multiple thing but no solution hopefully someone can assist.
Same issue happens with RDLC when download to excel is clicked
Please assist
Dim connection As String = ConfigurationManager.ConnectionStrings("ConnectionStringDirect").ConnectionString
Using con As New SqlConnection(connection)
Using cmd As New SqlCommand("Select Statement")
con.Open()
cmd.Connection = con
Dim sda As New SqlDataAdapter
sda.SelectCommand = cmd
Using dt As New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("COL0", GetType(String)), New DataColumn("COL1", GetType(String)), New DataColumn("COL2", GetType(String)), New DataColumn("COL3", GetType(String)), New DataColumn("COL4", GetType(String)), New DataColumn("COL5", GetType(String)), New DataColumn("COL6", GetType(String))})
sda.Fill(dt)
Using wb As New XLWorkbook()
Dim ws = wb.Worksheets.Add(dt, "EMS")
If dt.Rows.Count > 0 Then
ws.Cell("A1").Value = dt.Columns(0).ColumnName
ws.Cell("B1").Value = dt.Columns(1).ColumnName
ws.Cell("C1").Value = dt.Columns(2).ColumnName
ws.Cell("D1").Value = dt.Columns(3).ColumnName
ws.Cell("E1").Value = dt.Columns(4).ColumnName
ws.Cell("F1").Value = dt.Columns(5).ColumnName
ws.Cell("G1").Value = dt.Columns(6).ColumnName
For i As Integer = 0 To dt.Rows.Count - 1
ws.Cell("A" & (i + 2)).Value = dt.Rows(i)(0)
ws.Cell("B" & (i + 2)).Value = dt.Rows(i)(1)
ws.Cell("b" & (i + 2)).Style.DateFormat.Format = "dd/MM/yyyy"
ws.Cell("C" & (i + 2)).Value = dt.Rows(i)(2)
ws.Cell("E" & (i + 2)).Value = dt.Rows(i)(4)
ws.Cell("e" & (i + 2)).Style.DateFormat.Format = "dd/MM/yyyy"
ws.Cell("F" & (i + 2)).Value = dt.Rows(i)(5)
ws.Cell("f" & (i + 2)).Style.DateFormat.Format = "dd/MM/yyyy"
Next
End If
ws.Table(0).ShowAutoFilter = False ' Disable AutoFilter.
ws.Table(0).Theme = XLTableTheme.None ' Remove Theme.
ws.Columns().AdjustToContents() ' Resize all columns.
Response.Clear()
Response.ClearContent()
Response.Buffer = True
Response.Charset = ""
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment;filename=SqlExport.xlsx")
Using MyMemoryStream As New MemoryStream()
wb.SaveAs(MyMemoryStream)
MyMemoryStream.WriteTo(Response.OutputStream)
Response.Flush()
Response.End()
End Using
End Using
End Using
End Using
End Using