Reputation: 175
When using ClosedXML to export a Dataset's DataTables into multiple sheets I get hit with an error.
ClosedXML code I am using:
foreach (DataTable dt in dataSetSystemOwnerData.Tables)
{
var worksheet = workbook.Worksheets.Add(dt.TableName);
worksheet.Cell(1, 1).InsertTable(dt);
worksheet.Columns().AdjustToContents();
}
workbook.SaveAs(@"c:\temp\temp.xlsx");
workbook.Dispose();
I am getting the error on the line worksheet.Columns().AdjustToContents();
Error:
System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'
Upvotes: 0
Views: 752
Reputation: 21
It could be that a content of a field from the database was too long for the cell limit in Excel (32767 characters).
Try to do a SUBSTRING for the first 32000 characters for that field.
Upvotes: 2