You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2023/12/18 11:22:32 UTC

[Bug 68358] New: XWPFTable.addRow places copy of XWPFTableRow CTRow in XWPFTable CTTbl

https://bz.apache.org/bugzilla/show_bug.cgi?id=68358

            Bug ID: 68358
           Summary: XWPFTable.addRow places copy of XWPFTableRow CTRow in
                    XWPFTable CTTbl
           Product: POI
           Version: 5.2.3-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: dev@poi.apache.org
          Reporter: aanettomyys@gmail.com
  Target Milestone: ---

Here is sample code, which copy first row of table and populate it with some
text


    public static void sample(XWPFTable table) {
        final CTRow templateRow = (CTRow) table.getRow(0).getCtRow().copy();
        final XWPFTableRow tableRow = new XWPFTableRow((CTRow)
templateRow.copy(), table);
        tableRow.getCell(0).setText("Sample text"); // OK
        table.addRow(tableRow); // <-- cloned CTRow is copying
        tableRow.getCell(0).setText("Another sample text"); // <-- Modifying
old CTRow  
        // After writing document row still contain "Sample text"
    }

The problem is in method XWPFTable.addRow


   public void addRow(XWPFTableRow row) {
        ctTbl.addNewTr();
        ctTbl.setTrArray(getNumberOfRows() - 1, row.getCtRow()); // <-- copy
content of row CTRow
        tableRows.add(row); // <-- XWPFTableRow still points to own
row.getCtRow() and subsequent calls not affected final document
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 68358] XWPFTable.addRow places copy of XWPFTableRow CTRow in XWPFTable CTTbl

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68358

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 68358] XWPFTable.addRow places copy of XWPFTableRow CTRow in XWPFTable CTTbl

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=68358

Sayi <sa...@163.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |CLOSED
             Status|NEW                         |RESOLVED

--- Comment #1 from Sayi <sa...@163.com> ---
There is a way: get current ctrow and recreate tableRow(new XWPFTableRow(CTRow
row, XWPFTable table)).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org