I am trying to add table format after writing data into sheet. I came across this blog which has POI not NPOI implementation. So I tried writing slimier in C#.
Code I tried:
XSSFTable my_table = ((XSSFSheet)sheet).CreateTable();
CT_Table cttable = my_table.GetCTTable();
CT_TableStyleInfo table_style = new CT_TableStyleInfo();
cttable.tableStyleInfo = table_style;
table_style.name = "TableStyleMedium9";
table_style.showColumnStripes = false;
table_style.showRowStripes = true;
AreaReference my_data_range = new AreaReference(new CellReference(5, 0), new CellReference(10, 4));
cttable.@ref = my_data_range.FormatAsString();
cttable.displayName = "MYTABLE";
cttable.name = "Test";
cttable.id = 12;
Note:
Could not find alternate for
CTTableStyleInfo table_style = cttable.addNewTableStyleInfo();
as function addNewTableStyleInfo()
not available
so tried like
CT_TableStyleInfo table_style = new CT_TableStyleInfo();
cttable.tableStyleInfo = table_style;
While writing the stream to file:
(await workbook.ConfigureAwait(false)).Write(stream);
Getting Exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
StackTrace:
at NPOI.XSSF.UserModel.XSSFTable.UpdateHeaders()
at NPOI.XSSF.UserModel.XSSFTable.WriteTo(Stream out1)
at NPOI.XSSF.UserModel.XSSFTable.Commit()
at NPOI.POIXMLDocumentPart.OnSave(List`1 alreadySaved)
at NPOI.POIXMLDocumentPart.OnSave(List`1 alreadySaved)
at NPOI.POIXMLDocumentPart.OnSave(List`1 alreadySaved)
at NPOI.POIXMLDocument.Write(Stream stream)
at App..Facade.MainFacade.<BuildReportAsync>d__25.MoveNext() in C:\App..\MainFacade.cs:line 215
If I remove table part then working fine which means something wrong while table format. Please help.