Description: Some xlsx files when import and exported back to xlsx cannot be opened by LibreOffice Steps to Reproduce: 1. wget https://bugs.documentfoundation.org/attachment.cgi?id=122409 -O ~/Downloads/tdf97598-1.xlsx 2. ./instdir/program/soffice --headless --convert-to xlsx ~/Downloads/tdf97598-1.xlsx 3. ./instdir/program/soffice --headless --convert-to pdf ./tdf97598-1.xlsx Actual Results: warn:sc:873055:873055:sc/source/filter/oox/formulabase.cxx:1383: OpCodeProviderImpl::initFuncOpCode - no opcode mapping for function ODF 'ORG.OPENOFFICE.EASTERSUNDAY' <-> OOXML '_xlfn.ORG.OPENOFFICE.EASTERSUNDAY' warn:sc:873055:873055:sc/source/filter/oox/formulabase.cxx:1383: OpCodeProviderImpl::initFuncOpCode - no opcode mapping for function ODF 'ORG.OPENOFFICE.EASTERSUNDAY' <-> OOXML 'EASTERSUNDAY' warn:legacy.osl:873055:873055:sc/source/filter/oox/formulabase.cxx:1244: OpCodeProviderImpl::OpCodeProviderImpl - opcodes not initialized warn:oox:873055:873055:oox/source/core/xmlfilterbase.cxx:424: XmlFilterBase::importFragment - XML parser failed in fragment 'xl/workbook.xml' com.sun.star.uno.RuntimeException message: "invalid sheet index used at /home/caolan/LibreOffice/core/sc/source/filter/oox/workbookhelper.cxx:438" Error: source file could not be loaded Expected Results: successful roundtrip Reproducible: Always User Profile Reset: No Additional Info: not known if this ever worked
I wonder if this has anything to do with bug #162177 given the mention of "no opcode mapping for function ODF 'ORG.OPENOFFICE.EASTERSUNDAY' <-> OOXML '_xlfn.ORG.OPENOFFICE.EASTERSUNDAY'"
Sounds very likely. If I find time over the weekend / next week I can take a look at this / that change.
The EASTERSUNDAY name quirk is only an unrelated side condition, not the cause. Will fix separately as a follow-up for bug 162177. The invalid sheet index looks more relevant, and there are also a lot of warnings during save already in several different areas, among them loads of warn:legacy.osl:569730:569730:sc/source/filter/excel/xeformula.cxx:519: XclExpFmlaCompImpl::CreateFormula - unknown garbage behind formula and warn:legacy.osl:569730:569730:sc/source/filter/excel/xename.cxx:247: XclExpName::SetLocalTab - invalid sheet index
Something's utterly broken with that document. The original has sheets xl/worksheets/sheet1.xml xl/worksheets/sheet2.xml xl/worksheets/sheet3.xml xl/worksheets/sheet4.xml xl/worksheets/sheet5.xml with after loading all sheets except "Purchase order" (sheet2) hidden, but there are actually 10 sheets; 3 are scenario data (sample1,sample2,sample3) of which bug 97598 was about to not apply that data to the Purchase order sheet. xl/workbook.xml has <sheets> <sheet name="AutoOpen Stub Data" sheetId="1" state="veryHidden" r:id="rId1"/> <sheet name="Purchase order" sheetId="3" r:id="rId2"/> <sheet name="Macros" sheetId="4" state="veryHidden" r:id="rId3"/> <sheet name="ATW" sheetId="5" state="veryHidden" r:id="rId4"/> <sheet name="Lock" sheetId="6" state="veryHidden" r:id="rId5"/> <sheet name="Intl Data Table" sheetId="7" state="veryHidden" r:id="rId6"/> <sheet name="TemplateInformation" sheetId="8" state="veryHidden" r:id="rId7"/> </sheets> so 7 sheets, of which at least 2 (ATW, Lock) apparently are Excel internal drawing/database/template related structures. When saved to .xlsx again it results in xl/worksheets/sheet1.xml xl/worksheets/sheet2.xml xl/worksheets/sheet6.xml xl/worksheets/sheet7.xml xl/worksheets/sheet8.xml xl/worksheets/sheet9.xml xl/worksheets/sheet10.xml so 7 sheets, with the scenario data sheets omitted but the ATW and Lock sheets included. When loading that again the "bad sheet index" complained about is 8, greater than the number of sheets (but maybe file numbering would have to be taken into account). Fwiw, xl/workbook.xml then has <sheets> <sheet name="AutoOpen Stub Data" sheetId="1" state="hidden" r:id="rId3"/> <sheet name="Purchase order" sheetId="2" state="visible" r:id="rId4"/> <sheet name="Macros" sheetId="6" state="hidden" r:id="rId5"/> <sheet name="ATW" sheetId="7" state="hidden" r:id="rId6"/> <sheet name="Lock" sheetId="8" state="hidden" r:id="rId7"/> <sheet name="Intl Data Table" sheetId="9" state="hidden" r:id="rId8"/> <sheet name="TemplateInformation" sheetId="10" state="hidden" r:id="rId9"/> </sheets> Unassigning myself from this.
Created attachment 199412 [details] much smaller example to reproduce the issue This is a far simpler example that reproduces the problem. Apparently there are sheets that are not exported, but we write a localsheetid based on the calc tab index for xlsx, so on the reimport we have localsheetid's that are out of sync with that reality. for xls we use an index adjusted for what we export. So presumbly we could do that for xlsx too
Caolán McNamara committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/bf4fe0c2ba1d0a44cc07c6afba6d56b8adf8af50 tdf#164249 adjust XML_localSheetId to take into account not exported sheets It will be available in 25.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Caolán McNamara committed a patch related to this issue. It has been pushed to "libreoffice-25-2": https://git.libreoffice.org/core/commit/c6df63bf9d4731f7d1f2d7cc95f247c72f0e3045 tdf#164249 adjust XML_localSheetId to take into account not exported sheets It will be available in 25.2.2. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.