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 2018/09/25 19:13:08 UTC

[Bug 62758] New: createColumn corrupts XSSFTable

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

            Bug ID: 62758
           Summary: createColumn corrupts XSSFTable
           Product: POI
           Version: 4.0.0-FINAL
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: dmgauntt@uab.edu
  Target Milestone: ---

createColumn corrupts an XSSFTable by assigning the new column an ID equal to
the maximum ID of any existing column.  Unit test code is presented below. If
bApplyBugFix is false, Excel will report a corrupted file when the file is
open.  Otherwise, the file opens correctly.

It is possible the the bug fix for 62740 will fix this.

- David Gauntt

  public static void doUnitTest(File file) {
    final XSSFWorkbook workbook = new XSSFWorkbook();
    final XSSFSheet sheet = workbook.createSheet();

    createColumnUnitTest(sheet);

    try (OutputStream fileOut = new FileOutputStream(file)) {
      workbook.write(fileOut);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    } finally {
      try {
        workbook.close();
      } catch (IOException e) {
        System.err.println(e.getMessage());
      }
    }
    System.out.println("doUnitTest: done");
    final Desktop desktop = Desktop.getDesktop();
    try {
      desktop.open(file);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }

  }

  private static void createColumnUnitTest(XSSFSheet sheet) {
    final String procName = "createColumnUnitTest";
    final boolean bApplyBugFix = true;
    final int NUMCOLS = 3, NUMROWS = 4;

    System.out.println(String.format("\r\n%s: bFixBug=%s", procName,
bApplyBugFix));

    /* Fill a range with data */
    for (int i = 0; i < NUMROWS; i++) {
      XSSFRow row = sheet.createRow(i);
      for (int j = 0; j < NUMCOLS; j++) {
        XSSFCell localXSSFCell = row.createCell(j);
        if (i == 0) {
          localXSSFCell.setCellValue(String.format("Col%d", j + 1));
        } else {
          localXSSFCell.setCellValue(String.format("(%d,%d)", i + 1, j + 1));
        }
      }
    }

    /* Define a single column data range including headers */
    final AreaReference my_data_range = new AreaReference(new CellReference(0,
0),
        new CellReference(NUMROWS - 1, 1), SpreadsheetVersion.EXCEL2007);

    /* Create an object of type XSSFTable */
    final XSSFTable my_table = sheet.createTable(my_data_range);
    my_table.setDisplayName("testCreateColumn");

    /* Add a new column */
    System.out.println(my_table.getCTTable().toString());
    my_table.createColumn(null);
    my_table.updateHeaders();
    System.out.println(my_table.getCTTable().toString());

    if (bApplyBugFix) {
      final CTTable ctTable = my_table.getCTTable();
      final List<CTTableColumn> ctTableColumns =
ctTable.getTableColumns().getTableColumnList();
      final long numCols = ctTableColumns.size();
      for (int n = 0; n < numCols; ++n) {
        ctTableColumns.get(n).setId(n + 1);
      }
      System.out.println("After applying bug fix");
      System.out.println(my_table.getCTTable().toString());
    }

  }

-- 
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 62758] createColumn corrupts XSSFTable

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

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED
         Depends on|                            |62740

--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
Likely dup of 62740

*** This bug has been marked as a duplicate of bug 62740 ***


Referenced Bugs:

https://bz.apache.org/bugzilla/show_bug.cgi?id=62740
[Bug 62740] XSSFTable constructor automatically assigns invalid (non-unique)
column IDs
-- 
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