You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2026/06/14 13:53:51 UTC

(openoffice) branch AOO42X updated: Use the correct namespace when converting ODF formulas to MS Excel 2003 XML, so that R1C1 formula is used instead of leaving broken "of:=[.A1]" style references.

This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO42X
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/AOO42X by this push:
     new 90d689f1c2 Use the correct namespace when converting ODF formulas to MS Excel 2003 XML, so that R1C1 formula is used instead of leaving broken "of:=[.A1]" style references.
90d689f1c2 is described below

commit 90d689f1c2f4786c8eccf3c3d9498e76333baa4d
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Nov 16 21:30:03 2025 +0200

    Use the correct namespace when converting ODF formulas to MS Excel 2003 XML,
    so that R1C1 formula is used instead of leaving broken "of:=[.A1]" style
    references.
    
    Patch by: me
    Fixes: https://bz.apache.org/ooo/show_bug.cgi?id=96018
    
    (cherry picked from commit b045a72bbf8ebfd2ea5838734aa14f879ef23ec9)
---
 .../source/xslt/export/spreadsheetml/formular.xsl  |  11 ++-
 .../fvt/uno/sc/formula/TestFormulaRoundTrip.java   | 101 +++++++++++++++++++++
 2 files changed, 107 insertions(+), 5 deletions(-)

diff --git a/main/filter/source/xslt/export/spreadsheetml/formular.xsl b/main/filter/source/xslt/export/spreadsheetml/formular.xsl
index f3ed4c1d29..7243b27bde 100644
--- a/main/filter/source/xslt/export/spreadsheetml/formular.xsl
+++ b/main/filter/source/xslt/export/spreadsheetml/formular.xsl
@@ -47,8 +47,9 @@
 	xmlns:xt="http://www.jclark.com/xt"
 	xmlns:common="http://exslt.org/common"
 	xmlns:xalan="http://xml.apache.org/xalan"
+	xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
 	xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink xt common xalan">
+	exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink xt common xalan of">
 
 
 	<!-- Mapping @table:formula to @ss:Formula translating the expression syntax -->
@@ -85,14 +86,14 @@
 			<xsl:when test="$expression != ''">
 				<xsl:choose>
 					<!-- OASIS Open Document XML formular expressions  -->
-					<xsl:when test="starts-with($expression,'oooc:')">
-						<!-- giving out the '=', which will be removed with 'oooc:=' to enable recursive string parsing  -->
+					<xsl:when test="starts-with($expression,'of:')">
+						<!-- giving out the '=', which will be removed with 'of:=' to enable recursive string parsing  -->
 						<xsl:text>=</xsl:text>
 						<xsl:call-template name="function-parameter-mapping">
 							<xsl:with-param name="rowPos" select="$rowPos" />
 							<xsl:with-param name="columnPos" select="$columnPos" />
-							<!-- 1) remove 'oooc:=' prefix and exchange ';' with ',' -->
-							<xsl:with-param name="expression" select="translate(substring($expression,7),';',',')"/>
+							<!-- 1) remove 'of:=' prefix and exchange ';' with ',' -->
+							<xsl:with-param name="expression" select="translate(substring($expression,5),';',',')"/>
 						</xsl:call-template>
 					</xsl:when>
 					<xsl:otherwise>
diff --git a/test/testuno/source/fvt/uno/sc/formula/TestFormulaRoundTrip.java b/test/testuno/source/fvt/uno/sc/formula/TestFormulaRoundTrip.java
new file mode 100644
index 0000000000..a1c2894732
--- /dev/null
+++ b/test/testuno/source/fvt/uno/sc/formula/TestFormulaRoundTrip.java
@@ -0,0 +1,101 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+package fvt.uno.sc.formula;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SCUtil;
+import static testlib.uno.TestUtil.*;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.table.XCell;
+
+public class TestFormulaRoundTrip {
+	private UnoApp unoApp = new UnoApp();
+
+	private XSpreadsheetDocument scDocument = null;
+	private XComponent scComponent = null;
+
+	@Before
+	public void setUp() throws Exception {
+		unoApp.start();
+		scComponent = unoApp.newDocument("scalc");
+		scDocument = SCUtil.getSCDocument(scComponent);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(scComponent);
+		unoApp.close();
+	}
+
+	@Test
+	public void testMSExcel2003XMLFormulaRoundTrip() throws Exception {
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		SCUtil.setTextToCell(sheet, 0, 0, "Hello world");
+		SCUtil.setFormulaToCell(sheet, 0, 1, "=A1");
+		String formulaValue = SCUtil.getTextFromCell(sheet, 0, 1);
+		assertEquals("Hello world", formulaValue);
+
+		String storeUrl = Testspace.getUrl("output/sc/temp.xml");
+		PropertyValue[] storeProps = new PropertyValue[2];
+		storeProps[0] = new PropertyValue();
+		storeProps[0].Name = "FilterName";
+		storeProps[0].Value = "MS Excel 2003 XML";
+		storeProps[1] = new PropertyValue();
+		storeProps[1].Name = "Overwrite";
+		storeProps[1].Value = new Boolean(true);
+		XStorable scStorable =
+			(XStorable) UnoRuntime.queryInterface(XStorable.class, scComponent);
+		scStorable.storeAsURL(storeUrl, storeProps);
+
+		unoApp.closeDocument(scComponent);
+
+		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
+			XSpreadsheetDocument.class, unoApp.loadDocument(Testspace.getPath("output/sc/temp.xml")));
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		String formulaValue2 = SCUtil.getTextFromCell(sheet, 0, 1);
+		assertEquals("Hello world", formulaValue2);
+		String formula2 = SCUtil.getFormulaFromCell(sheet, 0, 1);
+		assertEquals("=A1", formula2);
+	}
+}