I use POI 3.1 to generate a xlsx file.
我使用POI 3.1生成xlsx文件。
This character ' is added automcally in my cell
这个字符'在我的单元格中自动添加
cell = row.createCell(0);
cell.setCellValue(atm.getEnvelop());
cell = row.createCell(1);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue(atm.getAmount().replace(".", ","));
atm.getEnvelop() and atm.getAmount() are string
atm.getEnvelop()和atm.getAmount()是字符串
atm.getEnvelop() value is 8635 but when i check in the file generated i get:' 8635
atm.getEnvelop()值是8635但是当我检查生成的文件时我得到:'8635
same thing for the other one
另一个是同样的事情
value is 200,00 i get '200,00
价值是200,00我得到'200,00
any idea?
任何想法?
3 个解决方案
#1
6
Your problem is that you're calling cell.setCellValue(String)
, which automatically sets the cell type to be a string
您的问题是您正在调用cell.setCellValue(String),它会自动将单元格类型设置为字符串
If you want to set a numeric cell type (so there's no '
prefixed in Excel), you need to give Apache POI a number not a string.
如果要设置数字单元格类型(因此Excel中没有“前缀”),则需要为Apache POI指定一个不是字符串的数字。
This code will set '200.00
in Excel:
此代码将在Excel中设置为“200.00:
String s200 = "200.00";
cell.setCellValue(s200);
While this one will give you 200.00
in Excel:
虽然这个将在Excel中给你200.00:
// Once per workbook - tell excel to format with with two decimal points
DataFormat fmt = wb.createDataFormat()
CellStyle cs = wb.createCellStyle();
cs.setDataFormat(fmt.getFormat("0.00"));
// Once per cell
double d200 = 200.0;
cell.setCellValue(d200);
cell.setCellStyle(cs);
For your case, where your number seems to be coming in as a String, you'll need to parser it into a number (eg double) before giving it to POI
对于您的情况,您的数字似乎是以字符串形式出现的,您需要先将其解析为数字(例如,双倍),然后再将其提供给POI
#2
1
AT the place of cell.setCellType(Cell.CELL_TYPE_NUMERIC); Use cell.setCellType(CELL_TYPE_STRING);
在cell.setCellType(Cell.CELL_TYPE_NUMERIC)的地方;使用cell.setCellType(CELL_TYPE_STRING);
Because putting char '' is excel property for numeric value.
因为将char''作为数值的excel属性。
it could help you.
它可以帮助你。
#3
0
I am not sure but I am guessing you are trying to get an integer from a cell of Cell.Cell_TYPE_STRING. Try to get the amount from cell by calling this : cell.getNumericCellValue()
我不确定,但我猜你试图从Cell.Cell_TYPE_STRING的单元格中获取一个整数。尝试通过调用以下方法从单元格中获取金额:cell.getNumericCellValue()
#1
6
Your problem is that you're calling cell.setCellValue(String)
, which automatically sets the cell type to be a string
您的问题是您正在调用cell.setCellValue(String),它会自动将单元格类型设置为字符串
If you want to set a numeric cell type (so there's no '
prefixed in Excel), you need to give Apache POI a number not a string.
如果要设置数字单元格类型(因此Excel中没有“前缀”),则需要为Apache POI指定一个不是字符串的数字。
This code will set '200.00
in Excel:
此代码将在Excel中设置为“200.00:
String s200 = "200.00";
cell.setCellValue(s200);
While this one will give you 200.00
in Excel:
虽然这个将在Excel中给你200.00:
// Once per workbook - tell excel to format with with two decimal points
DataFormat fmt = wb.createDataFormat()
CellStyle cs = wb.createCellStyle();
cs.setDataFormat(fmt.getFormat("0.00"));
// Once per cell
double d200 = 200.0;
cell.setCellValue(d200);
cell.setCellStyle(cs);
For your case, where your number seems to be coming in as a String, you'll need to parser it into a number (eg double) before giving it to POI
对于您的情况,您的数字似乎是以字符串形式出现的,您需要先将其解析为数字(例如,双倍),然后再将其提供给POI
#2
1
AT the place of cell.setCellType(Cell.CELL_TYPE_NUMERIC); Use cell.setCellType(CELL_TYPE_STRING);
在cell.setCellType(Cell.CELL_TYPE_NUMERIC)的地方;使用cell.setCellType(CELL_TYPE_STRING);
Because putting char '' is excel property for numeric value.
因为将char''作为数值的excel属性。
it could help you.
它可以帮助你。
#3
0
I am not sure but I am guessing you are trying to get an integer from a cell of Cell.Cell_TYPE_STRING. Try to get the amount from cell by calling this : cell.getNumericCellValue()
我不确定,但我猜你试图从Cell.Cell_TYPE_STRING的单元格中获取一个整数。尝试通过调用以下方法从单元格中获取金额:cell.getNumericCellValue()