使用POI,如何设置电池类型为数字 [英] using poi , How to set the Cell type as number

查看:148
本文介绍了使用POI,如何设置电池类型为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用POI 3.6

I am using poi 3.6

我能够正确地创建Excel。但是,当我试图设置单元格类型的数字,它总是给我的细胞类型一般。

I am able to create the excel properly. But when I trying to set the cell type as number , it always give me cell type as general.

即。在新创建的Excel中,当我点击右键,进入格式化细胞 - >还有我总是发现号是一个常规

i.e. In the newly create excel , when I right click and go to format cell ->there I always found number to be a General.

我的code是这样

style.setAlignment(CellStyle.ALIGN_RIGHT);
dataCell.setCellValue(Float.parseFloat(value as String);
dataCell.setCellType(Cell.CELL_TYPE_NUMERIC);
dataCell.setCellStyle(style);

您可以请建议这里是什么不见了?

Can you please suggest what is missing here ?

推荐答案

您可以试试这个方法太:

You can try this approach too:

HSSFRow row = sheet.createRow(sheet.getLastRowNum());
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = workbook.createCellStyle();
style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
cell.setCellStyle(style);
cell.setCellValue(Float.parseFloat("21.5"));

当然,看一看的<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFDataFormat.html\">documentation约数据格式范例

这篇关于使用POI,如何设置电池类型为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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