setCellType(HSSFCELL.CELL_TYPE_NUMERIC) 在 apache poi 中不起作用 [英] setCellType(HSSFCELL.CELL_TYPE_NUMERIC) is not working in apache poi

查看:47
本文介绍了setCellType(HSSFCELL.CELL_TYPE_NUMERIC) 在 apache poi 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SetCellType(HSSFCELL.CELL_TYPE_NUMERIC) 在 apache poi 中不起作用.有谁在JAVA中使用过POI的这个功能吗?

SetCellType(HSSFCELL.CELL_TYPE_NUMERIC) is not working in apache poi. Anyone have used this feature of POI in JAVA?

当我使用 POI 创建 XLS 文件并且单元格包含整数值并且我将单元格类型设置为数字时,该单元格反映了其他一些整数值.例子:使用 JAVA 程序和 poi 实用程序,我输入了 Cell A1"5".现在此单元格包含整数值,但默认情况下单元格类型为 CELL_TYPE_STRING.所以这个单元格给了我错误,并要求我将此单元格转换为数字.但是当我将此单元格类型设置为 CELL_TYPE_NUMERIC 时使用程序,它不会在 XLS 文件中给我错误,但它会显示不同的值.

When I created XLS file using POI and cell contains integer value and I set cell type as numeric at that time that cell reflects some other integer value. Example: Using JAVA program and poi utility, I am putting in Cell A1 value "5". Now this cell contains Integer value but by default cell type is CELL_TYPE_STRING. So this cell gives me error and asked me to convert this cell to Number. But using program when I will set this cell type as CELL_TYPE_NUMERIC at that time it does not give me error in XLS file but it shows me different value.

有人遇到过这样的问题吗?如果是,那么是否有任何解决方案.我坚持了这个.

Anyone has faced such issue? If yes then is there any solution for this. I stuck up with this one.

如果您需要更多说明,请询问我.

Please ask me if you need some more clarification.

提前致谢.

推荐答案

由于您使用的是 XSSF 而不是 HSSF,请使用 cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC) 而不是 setCellType(HSSFCELL.CELL_TYPE_NUMERIC).

Since you are using XSSF not HSSF, use cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC) instead of setCellType(HSSFCELL.CELL_TYPE_NUMERIC).

这篇关于setCellType(HSSFCELL.CELL_TYPE_NUMERIC) 在 apache poi 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆