sc/source/filter/excel/xestream.cxx | 2 + sc/source/filter/excel/xistyle.cxx | 39 ++++++++++++++++++++++++------------ sc/source/filter/inc/xistyle.hxx | 2 - 3 files changed, 29 insertions(+), 14 deletions(-)
New commits: commit 6a8f9130124781c0f75e758bc960464f56160cfe Author: Karthik Godha <[email protected]> AuthorDate: Thu Jan 1 15:49:25 2026 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Thu Jan 8 18:03:38 2026 +0100 tdf#170189: XLS->XLSX empty font-name in export <font> element in xl/styles.xml can't contaim empty "val" attribute in its name Change-Id: Ib476f23010a54f64cf90619f2712082785e4526a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196387 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Stahl <[email protected]> diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index c860d6c6d6ae..2c99632b5d34 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -900,6 +900,8 @@ sax_fastparser::FSHelperPtr XclXmlUtils::WriteFontData( sax_fastparser::FSHelper pStream->singleElement(XML_color, XML_rgb, XclXmlUtils::ToOString(rComplexColor.getFinalColor())); } + + assert(!rFontData.maName.isEmpty() && "Font Name can't be empty"); pStream->singleElement(nFontId, XML_val, rFontData.maName); pStream->singleElement(XML_family, XML_val, OString::number( rFontData.mnFamily )); if (rFontData.mnCharSet != 0) diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx index b42bfeed12a3..e2b9a53bb4c1 100644 --- a/sc/source/filter/excel/xistyle.cxx +++ b/sc/source/filter/excel/xistyle.cxx @@ -568,34 +568,47 @@ const XclImpFont* XclImpFontBuffer::GetFont( sal_uInt16 nFontIndex ) const This also means that entries above 4 are out by one in the list. */ if (nFontIndex == 4) + { return &maFont4; - - if (nFontIndex < 4) + } + else if (nFontIndex < 4) { // Font ID is zero-based when it's less than 4. - return nFontIndex >= maFontList.size() ? nullptr : &maFontList[nFontIndex]; + if (nFontIndex < maFontList.size() && maFontList[nFontIndex].has_value()) + return &maFontList[nFontIndex].value(); } - - // Font ID is greater than 4. It is now 1-based. - return nFontIndex > maFontList.size() ? nullptr : &maFontList[nFontIndex-1]; + else + { + // Font ID is greater than 4. It is now 1-based. + if (--nFontIndex < maFontList.size() && maFontList[nFontIndex].has_value()) + return &maFontList[nFontIndex].value(); + } + return nullptr; } void XclImpFontBuffer::ReadFont( XclImpStream& rStrm ) { - maFontList.emplace_back( GetRoot() ); - XclImpFont& rFont = maFontList.back(); - rFont.ReadFont( rStrm ); + XclImpFont aFont(GetRoot()); + aFont.ReadFont(rStrm); + + // If font-name is empty, remove it from the list + if (aFont.GetFontData().maName.isEmpty()) + { + maFontList.emplace_back(std::nullopt); + return; + } + maFontList.emplace_back(aFont); - if( maFontList.size() == 1 ) + if (maFontList.size() == 1) { - UpdateAppFont( rFont.GetFontData(), rFont.HasCharSet() ); + UpdateAppFont(aFont.GetFontData(), aFont.HasCharSet()); } } void XclImpFontBuffer::ReadEfont( XclImpStream& rStrm ) { - if( !maFontList.empty() ) - maFontList.back().ReadEfont( rStrm ); + if (!maFontList.empty() && maFontList.back().has_value()) + maFontList.back().value().ReadEfont(rStrm); } void XclImpFontBuffer::FillToItemSet( diff --git a/sc/source/filter/inc/xistyle.hxx b/sc/source/filter/inc/xistyle.hxx index ff56c5d1d370..e0839f9d686c 100644 --- a/sc/source/filter/inc/xistyle.hxx +++ b/sc/source/filter/inc/xistyle.hxx @@ -193,7 +193,7 @@ private: void UpdateAppFont( const XclFontData& rFontData, bool bHasCharSet ); private: - std::vector< XclImpFont > maFontList; /// List of all FONT records in the Excel file. + std::vector<std::optional<XclImpFont>> maFontList; /// List of all FONT records in the Excel file. XclFontData maAppFont; /// Application font (for column width). XclImpFont maFont4; /// Built-in font with index 4. XclImpFont maCtrlFont; /// BIFF5 default form controls font (Helv,8pt,bold).
