Hello,
When attempting to export a manually created workbook I obtain this error message:
Value cannot be null.
Parameter name: workbook at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Utilities.XlsxHelper.ConvertColumnPixelWidthToExcelWidth(Workbook workbook, Double columnWidthInPixels)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorksheetExportContext..ctor(XlsxWorkbookExportContext workbookContext, Worksheet worksheet, Int32 sheetNo)
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorkbookExportContext.InitializeWorksheetContexts()
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.XlsxWorkbookExportContext.Initialize()
at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ExportOverride(Workbook workbook, Stream output)
at [Redacted] Controller.cs:line 203
I Generate the workbook using this method:
public Workbook WriteExcelFile(List<Object> list)
{
Workbook workbook = new Workbook();
using (Worksheet worksheet = workbook.Worksheets.Add())
{
CellRange range = new CellRange(1, 1, list.Count, 5);
CellSelection selection = worksheet.Cells[range];
if (selection.CanInsertOrRemove(range, ShiftType.Right))
{
selection.Insert(InsertShiftType.Right);
}
for (int row = 0; row < list.Count; row++)
{
worksheet.Cells[row, 0].SetValue(list[row].string1);
worksheet.Cells[row, 1].SetValue(list[row].string2);
worksheet.Cells[row, 2].SetValue(list[row].string3);
worksheet.Cells[row, 3].SetValue(list[row].string4);
worksheet.Cells[row, 4].SetValue(list[row].string5);
}
}
return workbook;
}
The attempt to write it to a memory stream (FileStream was also attempted)
using (Stream output = new MemoryStream(10000))
formatProvider.Export(workbook, output);
Could you help me understand the reason behind this error?