Bug 65896

Summary: XSLFTable::mergeCells ineffective in single column tables
Product: POI Reporter: Simon Davey <apache>
Component: XSLFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 5.2.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Testcase and Workaround demo - source
Testcase and Workaround demo - output
Testcase and Workaround demo - output (screenshot)

Description Simon Davey 2022-02-17 12:44:01 UTC
Created attachment 38200 [details]
Testcase and Workaround demo - source

We have found an issue where the POI XSLFTable::mergeCells method seems ineffective at setting rowspans if the table only has a single column.

We have seen that POI is setting the rowspan=... attribute in the output Slide XML, however MS PowerPoint is ignoring it. Trying the same cell merging manually in PowerPoint GUI reveals that instead of setting rowspan, PowerPoint will remove the spanned-over rows and set the height of the first row to the total of the spanned over rows.

This makes me wonder if the POI XSLFTable::mergeCells method needs an update to mimick this technique along the lines of:

    if (tbl.getNumberOfColumns() == 1) {
      double h = tbl.getRowHeight(fromRow);
      // accumulate spanned-over row heights as we remove them
      for (int r = toRow; r > fromRow; --r) {
        h += tbl.getRowHeight(r);
        tbl.removeRow(r);
      }
      tbl.setRowHeight(fromRow, h);
    }
    else {
      tbl.mergeCells(fromRow, toRow, fromCol, toCol);
    }
Comment 1 Simon Davey 2022-02-17 12:44:33 UTC
Created attachment 38201 [details]
Testcase and Workaround demo - output
Comment 2 Simon Davey 2022-02-17 12:45:04 UTC
Created attachment 38202 [details]
Testcase and Workaround demo - output (screenshot)