ODF Toolkit
  1. ODF Toolkit
  2. ODFTOOLKIT-106

OdfTable.removeColumnsByIndex gives "java.lang.IllegalArgumentException: index should be nonnegative integer"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: odfdom-0.8.5
    • Fix Version/s: odfdom-0.8.7
    • Component/s: java
    • Labels:
      None
    • Environment:
      Operating System: Linux
      Platform: PC

      Description

      I created a new Spreadsheet document. I then deleted all tables that had been added to it. I then created a new table, and it started with 2 rows and 5 columns for some reason. I decided to delete them. Attempted deletion of the columns gave the error

      OdfDocument doc = null;
      String filename = "test.ods";

      File file = new File(filename);
      if (!file.exists())
      {
      // ODF spreadsheet doesn't exist, so create
      System.out.println(">> OdfDocument.newSpreadsheetDocument()");
      doc = OdfSpreadsheetDocument.newSpreadsheetDocument();

      // Delete any tables that ODFDOM created for us
      List<OdfTable> tables = new ArrayList(doc.getTableList());
      System.out.println(">> numtables=" + tables.size());
      Iterator<OdfTable> tableIter = tables.iterator();
      while (tableIter.hasNext())

      { OdfTable tbl = tableIter.next(); tbl.remove(); System.out.println(">> table=" + tbl.getTableName()); }

      System.out.println(">> numtables(after)=" + doc.getTableList().size());
      System.out.println(">> OdfDocument.save(" + file + ")");
      doc.save(file);
      }

      // Load the document
      System.out.println(">> OdfDocument.loadDocument(" + file + ")");
      doc = OdfDocument.loadDocument(file);

      // Add the table and its columns
      OdfTable table = OdfTable.newTable(doc);
      String sheetName = "FirstSheet";
      table.setTableName(sheetName);

      // Delete any columns that ODFDOM created for us
      System.out.println(">> numcols=" + table.getColumnCount());
      System.out.println(">> calling table.removeColumnsByIndex(0, " + table.getColumnCount() + ")");
      table.removeColumnsByIndex(0, table.getColumnCount());
      System.out.println(">> numcols(after)=" + table.getColumnCount());

      // Delete any rows that ODFDOM created for us
      System.out.println(">> numrows=" + table.getRowCount());
      table.removeRowsByIndex(0, table.getRowCount());
      System.out.println(">> numrows(after)=" + table.getRowCount());

      Output from this simple app is as follows

      >> file=test.ods
      >> OdfDocument.newSpreadsheetDocument()
      >> numtables=1
      >> table=Sheet1
      >> numtables(after)=0
      >> OdfDocument.save(test.ods)
      >> OdfDocument.loadDocument(test.ods)
      >> numcols=5
      >> calling table.removeColumnsByIndex(0, 5)
      java.lang.IllegalArgumentException: index should be nonnegative integer.
      at org.odftoolkit.odfdom.doc.table.OdfTableRow.getCellByIndex(OdfTableRow.java:274)
      at org.odftoolkit.odfdom.doc.table.OdfTableRow.removeCellByIndex(OdfTableRow.java:928)
      at org.odftoolkit.odfdom.doc.table.OdfTable.removeColumnsByIndex(OdfTable.java:1150)
      at org.datanucleus.test.Main.main(Main.java:54)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:290)
      at java.lang.Thread.run(Thread.java:619)

      So I'm calling OdfTable.removeColumnsByIndex(0, 5) and it thinks some input is negative. Why ?

      How do I get a simple OdfSpreadsheet without any creation artifacts (tables, rows, columns) ?

        Issue Links

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              datanucleus
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development