Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: 17 MB a WB with only one WS having 29 rows and 11 columns???

$
0
0
Hi all,

I love ClosedXML. I've used it before to create WBs containing up to 20 WSs. Data source primarily .NET DataTables. I save these WBs files to a MSSQL DB as binary data. Most of these WBs are of size between 118 KB and 150 KB. That's pretty good.

Now I'm trying to create a WB with only one WS from a .NET DataTable that has a schema of 11 columns and returns only 29 rows. This one I don't save it to the database. I send it to the user's browser, so the user can open it or save it.

What happens actually is that IE returns a message stating that the WB can't be opened, thus the user is forced to save it to his/her PC. The resulting file is of size 17,211 KB. Something must be wrong here... Is there something wrong with my code? Any help is greatly appreciated. Thanks.
Dim xlWB As New XLWorkbook(XLEventTracking.Disabled)  
Dim xlWS = xlWB.Worksheets.Add("Report Name")
xlWS.Cell(1, 1).InsertTable(objDs.Tables(0).AsEnumerable())

Dim xlRange_Amount = xlWS.Range("C2:C" & xlWS.RowCount)
xlRange_Amount.Style.NumberFormat.Format = "$ #,##0.00"

xlWS.Columns.AdjustToContents()

Dim objMS As MemoryStream = Nothing
Dim arrByte As Byte()

objMS = New MemoryStream
xlWB.SaveAs(objMS)
arrByte = objMS.GetBuffer

Response.AddHeader("Content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
Response.AddHeader("Content-Disposition", "attachment; filename=Test.xlsx")
Response.BinaryWrite(arrByte)
Response.Flush()
Response.End()

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>