odftoolkit icon indicating copy to clipboard operation
odftoolkit copied to clipboard

Merged cells shouldn't propagate

Open blakemcbride opened this issue 7 months ago • 3 comments

I merged some columns on the first row. Every row I used afterword had the same columns merged. I have spent hours trying to get it not to do that. While there may be times when it is desired, it shouldn't default to that behavior or there should be a way to turn that feature off.

blakemcbride avatar May 29 '25 02:05 blakemcbride

@blakemcbride Could you please provide a test case that uses the API to do this so we can reproduce and fix this behaviour quickly?

svanteschubert avatar May 29 '25 06:05 svanteschubert

    private static void test() {
        try {
            OdfTableCell cell;

            // Create a new spreadsheet document
            OdfSpreadsheetDocument odsDoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
            odsDoc.getTableByName("Sheet1").remove();  // The original sheet has bad defaults.  Create my own.

            // Create a new table (sheet)
            OdfTable table = OdfTable.newTable(odsDoc, 1, 1);
            table.setTableName("My Table");

            // I am only merging on one row yet it is propagated to future rows!
            table.getCellRangeByPosition(0, 0, 3, 0).merge();

            // Set values in specific cells
            cell = table.getCellByPosition(0, 0);
            cell.setStringValue("Line 1");

            cell = table.getCellByPosition(0, 1);
            cell.setStringValue("Line 2");

            cell = table.getCellByPosition(0, 2);
            cell.setStringValue("Line 3");

            // Save the document
            saveSheet(odsDoc, "/tmp/Test.odf");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

blakemcbride avatar May 29 '25 13:05 blakemcbride

Any takers to test this out on the master branch and potentially provide a patch? I am pretty packed these days, and likely the next thing I like to fix/improve is the viewable text insertion/extraction for ODF...

svanteschubert avatar May 30 '25 17:05 svanteschubert