Skip to content

Commit

Permalink
Fixes #313 - OdfElement cloneNode omitted wrongly some ODF attributes…
Browse files Browse the repository at this point in the history
… for cloning
  • Loading branch information
svanteschubert authored and mistmist committed Jul 30, 2024
1 parent 279cbce commit 02e6bbf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,7 @@ public Node cloneNode(boolean deep) {
cloneElement.setAttribute(qname, item.getNodeValue());
} else {
qname = prefix + ":" + item.getLocalName();
if (!qname.equals("xml:id")
&& !qname.equals("office:value")
&& !qname.equals("calcext:value-type")
&& !qname.equals("office:value-type")) {
if (!qname.equals("xml:id")) {
cloneElement.setAttributeNS(item.getNamespaceURI(), qname, item.getNodeValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
import org.odftoolkit.odfdom.dom.OdfStylesDom;
import org.odftoolkit.odfdom.dom.element.office.OfficeMasterStylesElement;
import org.odftoolkit.odfdom.dom.element.office.OfficeSpreadsheetElement;
import org.odftoolkit.odfdom.dom.element.style.StyleFooterElement;
import org.odftoolkit.odfdom.dom.element.style.StyleFooterStyleElement;
import org.odftoolkit.odfdom.dom.element.style.StyleHeaderElement;
Expand Down Expand Up @@ -1106,6 +1107,34 @@ public void testGetCellAt() {
}
} catch (Exception e) {
Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e);
Assert.fail("testGetCellAt failed");
}
}

@Test
public void writeCellDataAndCloneSheet() {
try {
OdfSpreadsheetDocument ods =
(OdfSpreadsheetDocument)
OdfSpreadsheetDocument.loadDocument(
ResourceUtilities.getAbsoluteInputPath("template.ots"));

ods.getSpreadsheetTables().get(0).appendRow();
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(0).setStringValue("Row3");
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(1).setDateValue(Calendar.getInstance());
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(2).setDoubleValue(21.59);
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(3).setDoubleValue(12.0);
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(4).setDoubleValue(0.000005);
ods.getSpreadsheetTables().get(0).getRowByIndex(5).getCellByIndex(5).setStringValue("Comment3");
OfficeSpreadsheetElement contentRoot = ods.getContentRoot();
TableTableElement table = (TableTableElement) contentRoot.getChildNodes().item(0);
TableTableElement clonedTable = (TableTableElement) table.cloneNode(true);
contentRoot.appendChild(clonedTable);
ods.getSpreadsheetTables().get(1).setTableName("newSheet");
ods.save(ResourceUtilities.getTestOutputFile("clonedSheet.ods"));
} catch (Exception e) {
Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e);
Assert.fail("writeCellDataAndCloneSheet failed");
}
}

Expand Down Expand Up @@ -1179,6 +1208,7 @@ public void testTableInHeaderFooter() {

} catch (Exception ex) {
Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex);
Assert.fail("testTableInHeaderFooter failed");
}
}

Expand Down
Binary file not shown.

0 comments on commit 02e6bbf

Please sign in to comment.