Fixing bug 46551 - spelling mistakes in xSSFCell.checkBounds(). Also fixed 0/1-based index error for cell range checks in XSSF.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@735061 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c6cfb0360
commit
7dad2164cd
@ -88,6 +88,13 @@ public class HSSFCell implements Cell {
|
|||||||
/** Error Cell type (5) @see #setCellType(int) @see #getCellType() */
|
/** Error Cell type (5) @see #setCellType(int) @see #getCellType() */
|
||||||
public final static int CELL_TYPE_ERROR = 5;
|
public final static int CELL_TYPE_ERROR = 5;
|
||||||
|
|
||||||
|
private static final String FILE_FORMAT_NAME = "BIFF8";
|
||||||
|
/**
|
||||||
|
* The maximum number of columns in BIFF8
|
||||||
|
*/
|
||||||
|
private static final int LAST_COLUMN_NUMBER = 255; // 2^8 - 1
|
||||||
|
private static final String LAST_COLUMN_NAME = "IV";
|
||||||
|
|
||||||
public final static short ENCODING_UNCHANGED = -1;
|
public final static short ENCODING_UNCHANGED = -1;
|
||||||
public final static short ENCODING_COMPRESSED_UNICODE = 0;
|
public final static short ENCODING_COMPRESSED_UNICODE = 0;
|
||||||
public final static short ENCODING_UTF_16 = 1;
|
public final static short ENCODING_UTF_16 = 1;
|
||||||
@ -915,14 +922,12 @@ public class HSSFCell implements Cell {
|
|||||||
/**
|
/**
|
||||||
* @throws RuntimeException if the bounds are exceeded.
|
* @throws RuntimeException if the bounds are exceeded.
|
||||||
*/
|
*/
|
||||||
private void checkBounds(int cellNum) {
|
private static void checkBounds(int cellIndex) {
|
||||||
if (cellNum > 255) {
|
if (cellIndex < 0 || cellIndex > LAST_COLUMN_NUMBER) {
|
||||||
throw new IllegalArgumentException("You cannot have more than 255 columns "+
|
throw new IllegalArgumentException("Invalid column index (" + cellIndex
|
||||||
"in a given row (IV). Because Excel can't handle it");
|
+ "). Allowable column range for " + FILE_FORMAT_NAME + " is (0.."
|
||||||
}
|
+ LAST_COLUMN_NUMBER + ") or ('A'..'" + LAST_COLUMN_NAME + "')");
|
||||||
else if (cellNum < 0) {
|
}
|
||||||
throw new IllegalArgumentException("You cannot reference columns with an index of less then 0.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,6 @@ import org.apache.poi.ss.formula.FormulaType;
|
|||||||
import org.apache.poi.ss.formula.FormulaRenderer;
|
import org.apache.poi.ss.formula.FormulaRenderer;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.model.SharedStringsTable;
|
import org.apache.poi.xssf.model.SharedStringsTable;
|
||||||
import org.apache.poi.POIXMLException;
|
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
||||||
@ -57,10 +56,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellFormulaType;
|
|||||||
public final class XSSFCell implements Cell {
|
public final class XSSFCell implements Cell {
|
||||||
private static POILogger logger = POILogFactory.getLogger(XSSFCell.class);
|
private static POILogger logger = POILogFactory.getLogger(XSSFCell.class);
|
||||||
|
|
||||||
|
private static final String FILE_FORMAT_NAME = "BIFF12";
|
||||||
/**
|
/**
|
||||||
* The maximum number of columns in SpreadsheetML
|
* The maximum number of columns in SpreadsheetML
|
||||||
*/
|
*/
|
||||||
public static final int MAX_COLUMN_NUMBER = 16384; //2^14
|
public static final int MAX_COLUMN_NUMBER = 16384; // 2^14
|
||||||
|
private static final int LAST_COLUMN_NUMBER = MAX_COLUMN_NUMBER-1;
|
||||||
|
private static final String LAST_COLUMN_NAME = "XFD";
|
||||||
|
|
||||||
private static final String FALSE_AS_STRING = "0";
|
private static final String FALSE_AS_STRING = "0";
|
||||||
private static final String TRUE_AS_STRING = "1";
|
private static final String TRUE_AS_STRING = "1";
|
||||||
@ -762,12 +764,11 @@ public final class XSSFCell implements Cell {
|
|||||||
/**
|
/**
|
||||||
* @throws RuntimeException if the bounds are exceeded.
|
* @throws RuntimeException if the bounds are exceeded.
|
||||||
*/
|
*/
|
||||||
private static void checkBounds(int cellNum) {
|
private static void checkBounds(int cellIndex) {
|
||||||
if (cellNum > MAX_COLUMN_NUMBER) {
|
if (cellIndex < 0 || cellIndex > LAST_COLUMN_NUMBER) {
|
||||||
throw new IllegalArgumentException("You cannot have more than "+MAX_COLUMN_NUMBER+" columns " +
|
throw new IllegalArgumentException("Invalid column index (" + cellIndex
|
||||||
"in a given row because Excel can't handle it");
|
+ "). Allowable column range for " + FILE_FORMAT_NAME + " is (0.."
|
||||||
} else if (cellNum < 0) {
|
+ LAST_COLUMN_NUMBER + ") or ('A'..'" + LAST_COLUMN_NAME + "')");
|
||||||
throw new IllegalArgumentException("You cannot reference columns with an index of less then 0.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import java.util.*;
|
|||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.POIXMLException;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
||||||
|
|
||||||
@ -30,6 +29,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
|||||||
*/
|
*/
|
||||||
public class XSSFRow implements Row, Comparable<XSSFRow> {
|
public class XSSFRow implements Row, Comparable<XSSFRow> {
|
||||||
|
|
||||||
|
private static final String FILE_FORMAT_NAME = "BIFF12";
|
||||||
/**
|
/**
|
||||||
* The maximum number of rows in SpreadsheetML
|
* The maximum number of rows in SpreadsheetML
|
||||||
*/
|
*/
|
||||||
@ -317,15 +317,16 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
/**
|
/**
|
||||||
* Set the row number of this row.
|
* Set the row number of this row.
|
||||||
*
|
*
|
||||||
* @param rowNum the row number (0-based)
|
* @param rowIndex the row number (0-based)
|
||||||
* @throws IllegalArgumentException if rowNum < 0 or greater than {@link #MAX_ROW_NUMBER}
|
* @throws IllegalArgumentException if rowNum < 0 or greater than {@link #MAX_ROW_NUMBER}
|
||||||
*/
|
*/
|
||||||
public void setRowNum(int rowNum) {
|
public void setRowNum(int rowIndex) {
|
||||||
if(rowNum < 0) throw new IllegalArgumentException("Row number must be >= 0");
|
if (rowIndex < 0 || rowIndex >= MAX_ROW_NUMBER) {
|
||||||
if (rowNum > MAX_ROW_NUMBER)
|
throw new IllegalArgumentException("Invalid row index (" + rowIndex
|
||||||
throw new IllegalArgumentException("You cannot have more than "+MAX_ROW_NUMBER+" rows ");
|
+ "). Allowable row range for " + FILE_FORMAT_NAME
|
||||||
|
+ " is (0.." + (MAX_ROW_NUMBER-1) + ")");
|
||||||
this.row.setR(rowNum + 1);
|
}
|
||||||
|
row.setR(rowIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -316,25 +316,25 @@ public final class TestXSSFCell extends TestCase {
|
|||||||
cell = row.createCell(100);
|
cell = row.createCell(100);
|
||||||
assertEquals("CW101", cell.getCTCell().getR());
|
assertEquals("CW101", cell.getCTCell().getR());
|
||||||
|
|
||||||
row = sheet.createRow(XSSFRow.MAX_ROW_NUMBER);
|
row = sheet.createRow(XSSFRow.MAX_ROW_NUMBER-1);
|
||||||
cell = row.createCell(100);
|
cell = row.createCell(100);
|
||||||
assertEquals("CW1048577", cell.getCTCell().getR());
|
assertEquals("CW1048576", cell.getCTCell().getR());
|
||||||
|
|
||||||
row = sheet.createRow(XSSFRow.MAX_ROW_NUMBER);
|
row = sheet.createRow(XSSFRow.MAX_ROW_NUMBER-1);
|
||||||
cell = row.createCell(XSSFCell.MAX_COLUMN_NUMBER);
|
cell = row.createCell(XSSFCell.MAX_COLUMN_NUMBER-1);
|
||||||
assertEquals("XFE1048577", cell.getCTCell().getR());
|
assertEquals("XFD1048576", cell.getCTCell().getR());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sheet.createRow(XSSFRow.MAX_ROW_NUMBER + 1);
|
sheet.createRow(XSSFRow.MAX_ROW_NUMBER);
|
||||||
fail("expecting exception when rownum > XSSFRow.MAX_ROW_NUMBER");
|
fail("expecting exception when rownum >= XSSFRow.MAX_ROW_NUMBER");
|
||||||
} catch(IllegalArgumentException e){
|
} catch(IllegalArgumentException e){
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
row = sheet.createRow(100);
|
||||||
try {
|
try {
|
||||||
row = sheet.createRow(100);
|
row.createCell(XSSFCell.MAX_COLUMN_NUMBER);
|
||||||
row.createCell(XSSFCell.MAX_COLUMN_NUMBER + 1);
|
fail("expecting exception when columnIndex >= XSSFCell.MAX_COLUMN_NUMBER");
|
||||||
fail("expecting exception when columnIndex > XSSFCell.MAX_COLUMN_NUMBER");
|
|
||||||
} catch(IllegalArgumentException e){
|
} catch(IllegalArgumentException e){
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user