red*_*x26 4 java excel apache-poi
我使用POI 3.1生成xlsx文件.
这个字符'在我的单元格中自动添加
cell = row.createCell(0);
cell.setCellValue(atm.getEnvelop());
cell = row.createCell(1);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue(atm.getAmount().replace(".", ","));
Run Code Online (Sandbox Code Playgroud)
atm.getEnvelop()和atm.getAmount()是字符串
atm.getEnvelop()值是8635但是当我检入生成的文件时我得到:'8635
另一个是同样的事情
价值是200,00我得到'200,00
任何的想法?
您的问题是您正在调用cell.setCellValue(String),它会自动将单元格类型设置为字符串
如果要设置数字单元格类型(因此'Excel中没有前缀),则需要为Apache POI指定一个不是字符串的数字.
此代码将'200.00在Excel中设置:
String s200 = "200.00";
cell.setCellValue(s200);
Run Code Online (Sandbox Code Playgroud)
虽然这个会200.00在Excel中给你:
// 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);
Run Code Online (Sandbox Code Playgroud)
对于您的情况,您的数字似乎是以字符串形式出现,您需要在将其分配给数字(例如,双倍)之前将其解析为POI
| 归档时间: |
|
| 查看次数: |
1608 次 |
| 最近记录: |