-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
NPOI Version
2.7.4 (or whichever version uses SixLabors.Fonts 1.0.1)
File Type
- XLSX
- XLS
- DOCX
- XLSM
- OTHER
Upload the Excel File
No file attached — issue can be reproduced with the code below.
Reproduce Steps
var workbook = new SXSSFWorkbook();
var sheet = (SXSSFSheet)workbook.CreateSheet("test");
var cell = sheet.CreateRow(0).CreateCell(0);
cell.SetCellValue("نام");
IFont font = workbook.CreateFont();
font.FontName = "B Nazanin";
cell.CellStyle = workbook.CreateCellStyle();
cell.CellStyle.SetFont(font);
sheet.TrackColumnForAutoSizing(0);
sheet.AutoSizeColumn(0);- Create a new
SXSSFWorkbookand sheet. - Add a cell with the value
"نام". - Set the font to
"B Nazanin". - Track column 0 for auto-sizing and call
AutoSizeColumn(0). - Observe crash.
Stack trace:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at SixLabors.Fonts.Tables.AdvancedTypographic.GSub.LookupType5Format2SubTable.TrySubstitution(FontMetrics fontMetrics, GSubTable table, GlyphSubstitutionCollection collection, Tag feature, Int32 index, Int32 count)
at SixLabors.Fonts.Tables.AdvancedTypographic.GSub.LookupTable.TrySubstitution(FontMetrics fontMetrics, GSubTable table, GlyphSubstitutionCollection collection, Tag feature, Int32 index, Int32 count)
at SixLabors.Fonts.Tables.AdvancedTypographic.GSubTable.ApplyFeature(FontMetrics fontMetrics, GlyphSubstitutionCollection collection, SkippingGlyphIterator& iterator, Tag& featureTag, ScriptClass current, Int32 index, Int32& count, Int32& i, Int32& collectionCount, Int32 maxCount, Int32 maxOperationsCount, Int32& currentOperations)
at SixLabors.Fonts.Tables.AdvancedTypographic.GSubTable.ApplySubstitution(FontMetrics fontMetrics, GlyphSubstitutionCollection collection)
at SixLabors.Fonts.StreamFontMetrics.ApplySubstitution(GlyphSubstitutionCollection collection)
at SixLabors.Fonts.FileFontMetrics.ApplySubstitution(GlyphSubstitutionCollection collection)
at SixLabors.Fonts.TextLayout.DoFontRun(ReadOnlySpan`1 text, Int32 start, IReadOnlyList`1 textRuns, Int32& textRunIndex, Int32& codePointIndex, Int32& bidiRunIndex, Boolean isFallbackRun, Font font, BidiRun[] bidiRuns, Dictionary`2 bidiMap, GlyphSubstitutionCollection substitutions, GlyphPositioningCollection positionings)
at SixLabors.Fonts.TextLayout.ProcessText(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextLayout.GenerateLayout(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextMeasurer.MeasureSize(ReadOnlySpan`1 text, TextOptions options)
at SixLabors.Fonts.TextMeasurer.MeasureSize(String text, TextOptions options)
at NPOI.SS.Util.SheetUtil.GetCellWidth(Int32 defaultCharWidth, Int32 colspan, ICellStyle style, Double width, String str, Font windowsFont, ICell cell)
at NPOI.SS.Util.SheetUtil.GetCellWidth(ICell cell, Int32 defaultCharWidth, DataFormatter formatter, Boolean useMergedCells)
at NPOI.SS.Util.SheetUtil.GetColumnWidthForRow(IRow row, Int32 column, Int32 defaultCharWidth, DataFormatter formatter, Boolean useMergedCells)
at NPOI.SS.Util.SheetUtil.GetColumnWidth(ISheet sheet, Int32 column, Boolean useMergedCells, Int32 firstRow, Int32 lastRow, Int32 maxRows)
at NPOI.SS.Util.SheetUtil.GetColumnWidth(ISheet sheet, Int32 column, Boolean useMergedCells, Int32 maxRows)
at NPOI.XSSF.Streaming.SXSSFSheet.AutoSizeColumn(Int32 column, Boolean useMergedCells)
at NPOI.XSSF.Streaming.SXSSFSheet.AutoSizeColumn(Int32 column)
Issue Description
When using B Nazanin font with SXSSFWorkbook and calling AutoSizeColumn, NPOI crashes because it depends on SixLabors.Fonts 1.0.1, which contains a bug with this font.
This bug is fixed in SixLabors.Fonts 2.0.1: SixLabors/Fonts#364
Proposed fix: update NPOI’s dependency on SixLabors.Fonts to >= 2.0.1.
Reactions are currently unavailable