Skip to content

Commit

Permalink
PL-8710 NumberFormat exception for single cell band
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Subbotin committed Apr 12, 2017
1 parent 40dfeab commit 9ee7215
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CellReference(String sheet, String cellRef) {
row = Integer.valueOf(matcher.group(2));
this.sheet = sheet;
} else {
throw new RuntimeException("Wrong cell " + cellRef);
throw new RuntimeException(String.format("Wrong cell %s", cellRef));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,34 @@ public static Range fromFormula(String range) {
Matcher matcher2 = SINGLE_CELL_RANGE_PATTERN.matcher(range);
if (matcher.find()) {
String sheet = matcher.group(1);

String startColumnStr = matcher.group(2);
String startRowStr = matcher.group(3);
String endColumnStr = matcher.group(4);
String endRowStr = matcher.group(5);
int startColumn = XlsxUtils.getNumberFromColumnReference(startColumnStr);
int startRow = Integer.valueOf(startRowStr);
int lastColumn = XlsxUtils.getNumberFromColumnReference(endColumnStr);
int lastRow = Integer.valueOf(endRowStr);
Range result = new Range(sheet, startColumn, startRow, lastColumn, lastRow);
return result;
try {
int startRow = Integer.valueOf(startRowStr);
int lastRow = Integer.valueOf(endRowStr);
int startColumn = XlsxUtils.getNumberFromColumnReference(startColumnStr);
int lastColumn = XlsxUtils.getNumberFromColumnReference(endColumnStr);
return new Range(sheet, startColumn, startRow, lastColumn, lastRow);
} catch (NumberFormatException e) {
throw new RuntimeException(String.format("Wrong range value %s. Error: %s", range, e.getMessage()));
}
} else if (matcher2.find()) {
String sheet = matcher2.group(1);

String startColumnStr = matcher2.group(2);
String startRowStr = matcher2.group(3);
int startColumn = XlsxUtils.getNumberFromColumnReference(startColumnStr);
int startRow = Integer.valueOf(startRowStr);
Range result = new Range(sheet, startColumn, startRow, startColumn, startRow);
return result;
int startRow;
try {
startRow = Integer.valueOf(startRowStr);
return new Range(sheet, startColumn, startRow, startColumn, startRow);
} catch (NumberFormatException e) {
throw new RuntimeException(String.format("Wrong range value %s. Error: %s", range, e.getMessage()));
}
} else {
throw new RuntimeException("Wrong range value " + range);
throw new RuntimeException(String.format("Wrong range value %s", range));
}
}

Expand All @@ -100,7 +106,7 @@ public static Range fromRange(String sheet, String range) {

return fromCells(sheet, firstCell, lastCell);
} else {
throw new RuntimeException("Wrong range value " + range);
throw new RuntimeException(String.format("Wrong range value %s", range));
}
}

Expand Down Expand Up @@ -253,7 +259,9 @@ public List<CellReference> toCellReferences() {
return references;
}

public boolean isOneCellRange() {return firstColumn == lastColumn && firstRow == lastRow;}
public boolean isOneCellRange() {
return firstColumn == lastColumn && firstRow == lastRow;
}

@Override
public boolean equals(Object o) {
Expand Down

0 comments on commit 9ee7215

Please sign in to comment.