sc/source/filter/excel/xestream.cxx | 7 +++++- sc/source/filter/excel/xetable.cxx | 38 +++++++++++++++++++++++++++++++++--- sc/source/filter/inc/xestream.hxx | 2 + 3 files changed, 43 insertions(+), 4 deletions(-)
New commits: commit 973d218475a071407cf3593ef9ab6243bc9c595c Author: Karthik Godha <[email protected]> AuthorDate: Tue Jan 13 21:17:30 2026 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Mon Jan 19 12:22:37 2026 +0100 XLS -> XLSX: Skip writing macros in formulas During XLS import, formulas containing named references which are not in ScRangeList are imported as macros. These are not handled during XLSX export. bug document: forum-en-1357.xls Change-Id: I6584117c4956ca1e0166bb0a15b19cee404154b7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197200 Reviewed-by: Michael Stahl <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx index c17d5cd6d706..5a1e65a3faf5 100644 --- a/sc/source/filter/excel/xestream.cxx +++ b/sc/source/filter/excel/xestream.cxx @@ -818,7 +818,12 @@ OUString XclXmlUtils::ToOUString( else { if (nErrCode != FormulaError::NONE) - aCompiler.AppendErrorConstant( aBuffer, nErrCode); + { + if (nErrCode == FormulaError::NoMacro) + aCompiler.AppendErrorConstant(aBuffer, FormulaError::NoRef); + else + aCompiler.AppendErrorConstant(aBuffer, nErrCode); + } else { // No code SHOULD be an "error cell", assert caller thought of that diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index e28f6b6e657f..5702f97be9f6 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -1015,15 +1015,47 @@ void XclExpFormulaCell::SaveXml( XclExpXmlStream& rStrm ) if (bWriteFormula) { + ScTokenArray aTokenArray(*mrScFmlaCell.GetCode()); + // If XLSX export then remove macro tokens from the array + if (!rStrm.IsExportVBA()) + { + formula::FormulaTokenArrayPlainIterator aIter(aTokenArray); + formula::FormulaToken* t = aIter.First(); + while (t) + { + if (t->GetOpCode() == ocMacro) + { + sal_uInt16 nStart = aIter.GetIndex() - 1; + formula::FormulaToken* pNext = aIter.PeekNext(); + if (pNext && pNext->GetOpCode() == ocOpen) + { + sal_uInt16 nParenthesis = 0; + do + { + if (pNext->GetOpCode() == ocOpen) + nParenthesis++; + else if (pNext->GetOpCode() == ocClose) + nParenthesis--; + + aIter.Next(); + pNext = aIter.PeekNext(); + } while (nParenthesis > 0 && pNext); + } + aTokenArray.RemoveToken(nStart, aIter.GetIndex() - nStart); + aIter.AfterRemoveToken(nStart, aIter.GetIndex() - nStart); + } + t = aIter.Next(); + } + } if (!bTagStarted) { rWorksheet->startElement( XML_f, XML_aca, ToPsz( (mxTokArr && mxTokArr->IsVolatile()) || (mxAddRec && mxAddRec->IsVolatile()) ) ); } - rWorksheet->writeEscaped( XclXmlUtils::ToOUString( - rStrm.GetRoot().GetCompileFormulaContext(), mrScFmlaCell.aPos, mrScFmlaCell.GetCode(), - mrScFmlaCell.GetErrCode())); + rWorksheet->writeEscaped(XclXmlUtils::ToOUString(rStrm.GetRoot().GetCompileFormulaContext(), + mrScFmlaCell.aPos, &aTokenArray, + mrScFmlaCell.GetErrCode())); rWorksheet->endElement( XML_f ); } diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx index ac2224c63787..05aa746d85a7 100644 --- a/sc/source/filter/inc/xestream.hxx +++ b/sc/source/filter/inc/xestream.hxx @@ -290,6 +290,8 @@ public: /** Returns the filter root data. */ const XclExpRoot& GetRoot() const { return *mpRoot; } + bool IsExportVBA() const { return mbExportVBA; } + sax_fastparser::FSHelperPtr& GetCurrentStream(); void PushStream( sax_fastparser::FSHelperPtr const & aStream ); void PopStream();
