From dea09bb73d14513cd6ba424bef29979c54ab01f4 Mon Sep 17 00:00:00 2001 From: dsyzov Date: Wed, 4 Nov 2026 16:35:56 +0000 Subject: [PATCH 1/2] fix(cell): carry preserved macro sheets through the editor x2t now puts Excel 4.0 macro sheets, which the editor has no model for, into an opaque PreservedSheets record (type 100) in Editor.bin. Keep its bytes on the workbook when the file is opened and write them back unchanged on save, so x2t can restore the sheets in the saved xlsm. Copy and paste does not carry the record. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: dsyzov --- cell/model/Serialize.js | 17 ++++++++++++++++- cell/model/Workbook.js | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cell/model/Serialize.js b/cell/model/Serialize.js index 157a82f450..8586a75729 100644 --- a/cell/model/Serialize.js +++ b/cell/model/Serialize.js @@ -307,7 +307,10 @@ RdRichValueTypes: 33, // Euro-Office extension: kept far above the ids above so that a record added later in the // same sequence cannot take it - SourceFileType: 100 + SourceFileType: 100, + // Euro-Office: sheets the editor cannot show (Excel 4.0 macro sheets). Opaque here; + // core writes and parses the payload. A high value keeps it clear of upstream ids. + PreservedSheets: 100 }; /** @enum */ var c_oSerWorkbookPrTypes = @@ -3840,6 +3843,11 @@ this.bs.WriteItem(c_oSerWorkbookTypes.ExternalReferences, function() {oThis.WriteExternalReferences();}); } if (!this.isCopyPaste) { + if (this.wb.preservedSheets) { + this.bs.WriteItem(c_oSerWorkbookTypes.PreservedSheets, function() { + oThis.memory.WriteBuffer(oThis.wb.preservedSheets, 0, oThis.wb.preservedSheets.length); + }); + } if (this.wb.oApi.vbaProject) { this.bs.WriteItem(c_oSerWorkbookTypes.VbaProject, function() { var old = new AscCommon.CMemory(true); @@ -9641,6 +9649,10 @@ this.oWorkbook.setOleSize(new AscCommonExcel.OleSizeSelectionRange(null, parsedRange)); } } + else if (c_oSerWorkbookTypes.PreservedSheets === type) + { + this.InitOpenManager.oReadResult.preservedSheets = this.stream.GetBufferUint8(length); + } else if (c_oSerWorkbookTypes.VbaProject === type) { let _end_rec = this.stream.cur + length; @@ -14044,6 +14056,7 @@ if (this.InitOpenManager.oReadResult.vbaProject) { wb.oApi.vbaProject = this.InitOpenManager.oReadResult.vbaProject; } + wb.preservedSheets = this.InitOpenManager.oReadResult.preservedSheets; wb.checkCorrectTables(); }; this.PostLoadPrepareDefNames = function(wb) @@ -14855,6 +14868,7 @@ pivotCacheDefinitions: {}, vbaMacros: null, vbaProject: null, + preservedSheets: null, macros: null, slicerCaches: {}, tableIds: {}, @@ -14904,6 +14918,7 @@ if (this.oReadResult.vbaProject) { wb.oApi.vbaProject = this.oReadResult.vbaProject; } + wb.preservedSheets = this.oReadResult.preservedSheets; wb.checkCorrectTables(); }; diff --git a/cell/model/Workbook.js b/cell/model/Workbook.js index 0f61309c89..97e265088b 100644 --- a/cell/model/Workbook.js +++ b/cell/model/Workbook.js @@ -3278,6 +3278,9 @@ // File type (Asc.c_oAscFileType) of the document the workbook was converted from, when the // converter recorded it; null otherwise. this.sourceFileType = null; + // Sheets the editor cannot show (Excel 4.0 macro sheets), as an opaque Uint8Array + // that is written back unchanged on save. + this.preservedSheets = null; AscFormat.ExecuteNoHistory(function () { this.CustomProperties = new AscCommon.CCustomProperties(); From 57b9fe84122cb4f31fe66eee303c04a3d22e5963 Mon Sep 17 00:00:00 2001 From: dsyzov Date: Thu, 26 Nov 2026 23:07:09 +0000 Subject: [PATCH 2/2] fix(cell): move the PreservedSheets record to workbook id 101 main took workbook record id 100 for SourceFileType, the same id PreservedSheets used, and the PreservedSheets branch is checked first on open, so a workbook converted from ODS would have kept its source file type as preserved sheets. core moves the record to 101 as well. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: dsyzov --- cell/model/Serialize.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cell/model/Serialize.js b/cell/model/Serialize.js index 8586a75729..deb2dababc 100644 --- a/cell/model/Serialize.js +++ b/cell/model/Serialize.js @@ -308,9 +308,10 @@ // Euro-Office extension: kept far above the ids above so that a record added later in the // same sequence cannot take it SourceFileType: 100, - // Euro-Office: sheets the editor cannot show (Excel 4.0 macro sheets). Opaque here; - // core writes and parses the payload. A high value keeps it clear of upstream ids. - PreservedSheets: 100 + // Euro-Office extension, next to SourceFileType: sheets the editor cannot show (Excel 4.0 + // macro sheets). Opaque here; core writes and parses the payload. The next Euro-Office + // record takes 102, here and in core (OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h). + PreservedSheets: 101 }; /** @enum */ var c_oSerWorkbookPrTypes =