diff --git a/main/SS/Formula/OperandClassTransformer.cs b/main/SS/Formula/OperandClassTransformer.cs index ea0f6d2cd3..a51454a587 100644 --- a/main/SS/Formula/OperandClassTransformer.cs +++ b/main/SS/Formula/OperandClassTransformer.cs @@ -114,11 +114,21 @@ private void TransformNode(ParseNode node, byte desiredOperandClass, // Note - the tAttrSum token (node.getToken()) is a base // token so does not need to have its operand class set } - if (token is ValueOperatorPtg || token is ControlPtg - || token is MemFuncPtg + if (token is MemFuncPtg || token is MemAreaPtg || token is UnionPtg || token is IntersectionPtg) + { + // Reference-type operators: children preserve the desired operand class. + // This ensures that Area3DPtg tokens inside union/intersection expressions + // (e.g. multiple print areas) keep CLASS_REF when used in a named range context. + for (int i = 0; i < children.Length; i++) + { + TransformNode(children[i], desiredOperandClass, callerForceArrayFlag); + } + return; + } + if (token is ValueOperatorPtg || token is ControlPtg) { // Value Operator Ptgs and Control are base Tokens, so Token will be unchanged // but any child nodes are processed according To desiredOperandClass and callerForceArrayFlag diff --git a/testcases/main/SS/UserModel/BaseTestWorkbook.cs b/testcases/main/SS/UserModel/BaseTestWorkbook.cs index d0c5233776..97baad56d2 100644 --- a/testcases/main/SS/UserModel/BaseTestWorkbook.cs +++ b/testcases/main/SS/UserModel/BaseTestWorkbook.cs @@ -388,6 +388,28 @@ public void TestPrintArea() workbook.Close(); } + [Test] + public void TestMultiplePrintArea() + { + IWorkbook workbook = _testDataProvider.CreateWorkbook(); + ISheet sheet1 = workbook.CreateSheet("Sheet1"); + String sheetName1 = sheet1.SheetName; + + // Set multiple print areas with comma-delimited references + String reference = "$A$1:$C$5,$E$6:$F$9"; + workbook.SetPrintArea(0, reference); + String retrievedPrintArea = workbook.GetPrintArea(0); + ClassicAssert.IsNotNull(retrievedPrintArea, "Multiple print area should not be null"); + // Both areas should be present with the sheet name prefix + ClassicAssert.IsTrue(retrievedPrintArea.Contains("$A$1:$C$5"), "First area should be present"); + ClassicAssert.IsTrue(retrievedPrintArea.Contains("$E$6:$F$9"), "Second area should be present"); + ClassicAssert.IsTrue(retrievedPrintArea.Contains(sheetName1), "Sheet name should be present"); + + workbook.RemovePrintArea(0); + ClassicAssert.IsNull(workbook.GetPrintArea(0)); + workbook.Close(); + } + [Test] public void TestGetSetActiveSheet() {