我想将数字数据存储在 excel 表中。
数值数据在我的java代码中用String类型表示。
是否可以将其设置为数字而不进行强制转换?
我试过下面的代码,但它没有转换为数字类型(我在 excel 中收到警告,说数字存储为文本...)
HSSFCell dCell =...
dCell.setCellType(Cell.CELL_TYPE_NUMERIC);
dCell.setCellValue("112.45")
最佳答案
您必须提供 double 值。作为the doc says :
setCellValue
public void setCellValue(double value)
set a numeric value for the cell
Parameters:
value - the numeric value to set this cell to. For formulas we'll set the precalculated value, for numerics we'll set its value. For other types we will change the cell to a numeric cell and set its value.
所以,应该是
dCell.setCellValue(new Double("123"));
或
dCell.setCellValue(123); //Remember, the way you did was, you actually passed a string (no quotes)
关于java - 使用 POI 以数字格式设置 Excel 单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967942/