Scott E
Scott E

Reputation: 175

Using ClosedXML getting A generic error occurred in GDI+ Error

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

Answers (1)

Martín Dopazo
Martín Dopazo

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

Related Questions