Missing font exception on Ubuntu since 0.101.0
See original GitHub issueDo you want to request a feature or report a bug?
- Bug
- Feature
- Question
Did you test against the latest CI build?
- Yes - tested with 0.101.999.3068
- No
Version of ClosedXML
0.101.0
What is the current behavior?
With 0.101.0 our automated tests on Github Linux/Ubuntu runner throw at new XLWorkbook(stream)
.
Unhandled exception. System.ArgumentException: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through 'LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine("Fallback font name")'. Additional information is available at https://closedxml.readthedocs.io/en/latest/tips/missing-font.html page.
at ClosedXML.Graphics.DefaultGraphicEngine.LoadFont(MetricId metricId)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ClosedXML.Graphics.DefaultGraphicEngine.GetFont(MetricId metricId)
at ClosedXML.Graphics.DefaultGraphicEngine.CalculateMaxDigitWidth(MetricId metricId)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ClosedXML.Graphics.DefaultGraphicEngine.GetMaxDigitWidth(IXLFontBase fontBase, Double dpiX)
at ClosedXML.Excel.XLWorkbook.CalculateColumnWidth(Double charWidth, IXLFont font, XLWorkbook workbook)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(Stream stream)
at ClosedXML.Excel.XLWorkbook.Load(Stream stream)
at ClosedXML.Excel.XLWorkbook..ctor(Stream stream, LoadOptions loadOptions)
at ClosedXML.Excel.XLWorkbook..ctor(Stream stream)
at Program.<Main>$(String[] args) in /home/jur/linuxrepos/external/closedxmlbug/Program.cs:line 3
The information at the URL is helpful for finding a workaround. In our case it’s a dumb implementation of IXLGraphicEngine where we just return default
in all methods. We are not using any AdjustToContent
and are just using XLWorkbook to read cell contents.
I think this is a bug in ClosedXML. Some reasons:
- We are not doing any
AdjustToContent
and the exception already happens atnew XLWorkbook(stream)
. - From a ClosedXML library perspective this makes it harder for people to start out with this library on systems (like Ubuntu) that don’t have the mentioned Calibri or Microsoft Sans Serif.
- Didn’t happen with any release before 0.101.0 and the release notes didn’t say anything about a breaking change.
https://github.com/ClosedXML/ClosedXML/commit/b655dc7a7334c991635dc82efc47153a353a39ef seems to have introduced this.
What is the expected behavior or new feature?
I would expect new XLWorkbook(stream)
to not require having installed any fonts.
Is this a regression from the previous version?
Reproducibility
Code to reproduce problem:
In standard Ubuntu installation with dotnet sdk installed. I’m using WSL locally. And our CI uses Github actions with ubuntu-latest
runner.
> dotnet new console
> dotnet add package ClosedXML
Program.cs:
using ClosedXML.Excel;
using var stream = File.OpenRead("./hello.xlsx");
_ = new XLWorkbook(stream);
- I attached a sample spreadsheet. hello.xlsx
Issue Analytics
- State:
- Created 5 months ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top GitHub Comments
Encountering this as well on GitHub Actions. Repro:
using var workbook = new XLWorkbook(File.OpenRead(excelFilePath))
Workaround:
Similar issue, and like @jr01 I don’t need to call
AdjustToContent
or do any saving at all. This workaround worked fine on v0.101.0 (Linux):