1. POI解析的时候比较吃内存. 因为一旦解析,估计就是整个workbook load的内存.
/**
* given a POI POIFSFileSystem object, read in its Workbook and populate the high and
* low level models. If you're reading in a workbook...start here.
*
* @param fs the POI filesystem that contains the Workbook stream.
* @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to. If set, will store all of the POIFSFileSystem
* in memory
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
* @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes)
throws IOException
{
this(fs.getRoot(), fs, preserveNodes);
}
set preserveNodes = false可能会节省点.
2. HSSFCell的值有这些类型
/** Numeric Cell type (0) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_NUMERIC = 0;
/** String Cell type (1) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_STRING = 1;
/** Formula Cell type (2) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_FORMULA = 2;
/** Blank Cell type (3) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_BLANK = 3;
/** Boolean Cell type (4) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_BOOLEAN = 4;
/** Error Cell type (5) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_ERROR = 5;
其实不得不说一下的就是Number, 它不管你是Integer还是浮点,返回的都是double.
而且把Date数据类型会组成一个奇怪的数字. 需要而外判断
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
double dValue = cell.getNumericCellValue();
if ( HSSFDateUtil.isCellDateFormatted(cell)) { //日期
return DateFormat.getDateInstance(DateFormat.DATE_FIELD).format(cell.getDateCellValue());
}
else if (this.doubleIsInteger(dValue)) {
return String.valueOf((int) dValue);
}
else {
return String.valueOf(cell.getNumericCellValue());
}
}
3. 从HSSFSheet拿出来的HSSFRow, 从HSSFRow拿出来的HSSFCell都有可能是Null, 注意判断.
4. 用户编辑很多Excel的时候会拉伸出很多空的行和列,注意过滤.
能免费使用都蛮好了的, Excel的内容乱七八糟的时候POI解析容易抛异常,旧的包有不少的bug, 最新release3.2要稳定些.
有bug就到apache的bugzilla记下吧,
.....
/**
* given a POI POIFSFileSystem object, read in its Workbook and populate the high and
* low level models. If you're reading in a workbook...start here.
*
* @param fs the POI filesystem that contains the Workbook stream.
* @param preserveNodes whether to preseve other nodes, such as
* macros. This takes more memory, so only say yes if you
* need to. If set, will store all of the POIFSFileSystem
* in memory
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
* @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes)
throws IOException
{
this(fs.getRoot(), fs, preserveNodes);
}
set preserveNodes = false可能会节省点.
2. HSSFCell的值有这些类型
/** Numeric Cell type (0) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_NUMERIC = 0;
/** String Cell type (1) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_STRING = 1;
/** Formula Cell type (2) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_FORMULA = 2;
/** Blank Cell type (3) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_BLANK = 3;
/** Boolean Cell type (4) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_BOOLEAN = 4;
/** Error Cell type (5) @see #setCellType(int) @see #getCellType() */
public final static int CELL_TYPE_ERROR = 5;
其实不得不说一下的就是Number, 它不管你是Integer还是浮点,返回的都是double.
而且把Date数据类型会组成一个奇怪的数字. 需要而外判断
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
double dValue = cell.getNumericCellValue();
if ( HSSFDateUtil.isCellDateFormatted(cell)) { //日期
return DateFormat.getDateInstance(DateFormat.DATE_FIELD).format(cell.getDateCellValue());
}
else if (this.doubleIsInteger(dValue)) {
return String.valueOf((int) dValue);
}
else {
return String.valueOf(cell.getNumericCellValue());
}
}
3. 从HSSFSheet拿出来的HSSFRow, 从HSSFRow拿出来的HSSFCell都有可能是Null, 注意判断.
4. 用户编辑很多Excel的时候会拉伸出很多空的行和列,注意过滤.
能免费使用都蛮好了的, Excel的内容乱七八糟的时候POI解析容易抛异常,旧的包有不少的bug, 最新release3.2要稳定些.
有bug就到apache的bugzilla记下吧,
.....