diff options
author | Yegor Kozlov <yegor@apache.org> | 2009-09-07 04:55:32 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2009-09-07 04:55:32 +0000 |
commit | 1559a6d4bd75f699e370a9593c033a3ff6113309 (patch) | |
tree | 442776515603859efd79712211255be949c3a977 /src/java | |
parent | 8c5838262e4a30b3d71093ed96979682d51052c6 (diff) | |
download | poi-1559a6d4bd75f699e370a9593c033a3ff6113309.tar.gz poi-1559a6d4bd75f699e370a9593c033a3ff6113309.zip |
Do not allow text longer than 32,767 characters in HSSF cells, see Bugzilla 47751
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@811994 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/org/apache/poi/hssf/usermodel/HSSFCell.java | 5 | ||||
-rwxr-xr-x | src/java/org/apache/poi/ss/SpreadsheetVersion.java | 21 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java index 29a46c5d34..999fa287dc 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java @@ -540,6 +540,11 @@ public class HSSFCell implements Cell { setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex); return; } + + if(hvalue.length() > SpreadsheetVersion.EXCEL97.getMaxTextLength()){ + throw new IllegalArgumentException("The maximum length of cell contents (text) is 32,767 characters"); + } + if (_cellType == CELL_TYPE_FORMULA) { // Set the 'pre-evaluated result' for the formula // note - formulas do not preserve text formatting. diff --git a/src/java/org/apache/poi/ss/SpreadsheetVersion.java b/src/java/org/apache/poi/ss/SpreadsheetVersion.java index 316e5af06f..d4edaec53f 100755 --- a/src/java/org/apache/poi/ss/SpreadsheetVersion.java +++ b/src/java/org/apache/poi/ss/SpreadsheetVersion.java @@ -36,9 +36,11 @@ public enum SpreadsheetVersion { * <li>The total number of available rows is 64k (2^16)</li> * <li>The maximum number of arguments to a function is 30</li> * <li>Number of conditional format conditions on a cell is 3</li> + * <li>Length of text cell contents is unlimited </li> + * <li>Length of text cell contents is 32767</li> * </ul> */ - EXCEL97(0x10000, 0x0100, 30, 3), + EXCEL97(0x10000, 0x0100, 30, 3, 32767), /** * Excel2007 @@ -49,21 +51,24 @@ public enum SpreadsheetVersion { * <li>The maximum number of arguments to a function is 255</li> * <li>Number of conditional format conditions on a cell is unlimited * (actually limited by available memory in Excel)</li> + * <li>Length of text cell contents is unlimited </li> * <ul> */ - EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE); + EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE, Integer.MAX_VALUE); private final int _maxRows; private final int _maxColumns; private final int _maxFunctionArgs; private final int _maxCondFormats; + private final int _maxTextLength; - private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats) { + private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats, int maxText) { _maxRows = maxRows; _maxColumns = maxColumns; _maxFunctionArgs = maxFunctionArgs; _maxCondFormats = maxCondFormats; - } + _maxTextLength = maxText; + } /** * @return the maximum number of usable rows in each spreadsheet @@ -116,4 +121,12 @@ public enum SpreadsheetVersion { public String getLastColumnName() { return CellReference.convertNumToColString(getLastColumnIndex()); } + + /** + * @return the maximum length of a text cell + */ + public int getMaxTextLength() { + return _maxTextLength; + } + } |