[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15000612#comment-15000612
 ] 

Raimund Hölle edited comment on ODFTOOLKIT-356 at 11/11/15 4:36 PM:
--------------------------------------------------------------------

And this is the reason and the solution:
Original code (still in trunk):
{code:title=Row.java|borderStyle=solid}
public Cell getCellByIndex(int index) {
  ...
  // expand column as needed.
  int lastColumnIndex = table.getColumnCount() - 1;
  if (index > lastColumnIndex) {
    // need clean cell style.
    table.appendColumns((index - lastColumnIndex), true);
  }
  ...
}
{code}
If getColumnCount() returns 0, the index for appendColumns() is -1.
Correct code:
{code:title=Row.java|borderStyle=solid}
    table.appendColumns(lastColumnIndex < 0 ? index + 1 : (index - 
lastColumnIndex), true);  
{code}
I've tested that solution, it works.


was (Author: profhccaesar):
And this is the reason and the solution:
Original code (still in trunk):
{code:title=Row.java|borderStyle=solid}
public Cell getCellByIndex(int index) {
  ...
  // expand column as needed.
  int lastColumnIndex = table.getColumnCount() - 1;
  if (index > lastColumnIndex) {
    // need clean cell style.
    table.appendColumns((index - lastColumnIndex), true);
  }
  ...
}
{code}
If getColumnCount() returns 0, the index for appendColumns() is -1.
Correct code:
{code:title=Row.java|borderStyle=solid}
  if (lastColumnIndex >= 0 && index > lastColumnIndex) {
{code}
I've tested that solution, it works.

> IllegalArgumentException when removing all columns from a fresh Table
> ---------------------------------------------------------------------
>
>                 Key: ODFTOOLKIT-356
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-356
>             Project: ODF Toolkit
>          Issue Type: Bug
>    Affects Versions: 0.6-incubating
>            Reporter: Florian Hopf
>            Assignee: Florian Hopf
>         Attachments: ODFTOOLKIT-356-Test.patch
>
>
> When trying to remove all columns from the Table of a newly created 
> SpreadsheetDocument an illegal index is passed in to Row#getCellByIndex()



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to