使用POI API在Excel中显示百分比值 [英] Display percentage values in Excel using POI API

查看:3246
本文介绍了使用POI API在Excel中显示百分比值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要12.3%的cell.but显示像Excel单元格的值应该可以
转换成number.by默认情况下它正在考虑为text.But我想把它当作一个数字。

i need to show a value in excel cell like in 12.3% in the cell.but it should be able convert into a number.by default it is considering as a text.But i want it as a number.

如果任何机构克服这个problem.please让我知道。

if any body overcome this problem.please let me know.

推荐答案

您需要:


  1. 设置您的数据作为数字(浮点),而不是文字。

  2. 指定单元格的格式为百分比。

是这样的:

cell.setCellValue(0.123); // set value as number
CellStyle style = workbook.createCellStyle();
style.setDataFormat(workbook.createDataFormat().getFormat("0.000%"));
cell.setCellStyle(style);

看看POI快速指南,为用户定义的格式部分更多细节。您可能还需要经过例子,显示了如何使用不同的POI功能。

Take a look at user defined formats section of POI quick guide for more details. You may also want to go through the examples which show how to use different POI capabilities.

这篇关于使用POI API在Excel中显示百分比值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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