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(".", ",")); 

atm.getEnvelop()和atm.getAmount()是string

atm.getEnvelop()值是8635,但是当我检查生成的文件,我得到:'8635

同样的事情为另一个

价值是200,00我得到'200,00

任何想法?

你的问题是你正在调用cell.setCellValue(String) ,它会自动将单元格types设置为一个string

如果你想设置一个数字单元格types(所以在Excel中没有前缀),你需要给Apache POI一个数字而不是string。

此代码将在Excel中设置'200.00

 String s200 = "200.00"; cell.setCellValue(s200); 

虽然这个会在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); 

对于你的情况,你的号码似乎是作为一个string进来,你需要parsing成一个数字(例如双),然后把它给POI

在cell.setCellType(Cell.CELL_TYPE_NUMERIC); 使用cell.setCellType(CELL_TYPE_STRING);

因为把char''放在数值的excel属性里。

它可以帮助你。

我不知道,但我猜你正在尝试从Cell.Cell_TYPE_STRING的单元格获取一个整数。 尝试通过调用这个来获取单元格的数量:cell.getNumericCellValue()