当前位置:网站首页>POI excel percentage
POI excel percentage
2022-07-03 06:53:00 【God】
The two methods :
One 、 String splicing :“20.36”+“%”,
Simple and direct ;
The disadvantage is that , Generated Excel You cannot directly create a statistical chart ( Not numbers , Manual format conversion required )
Two 、 Use POI Cell style :
// Create styles
HSSFCellStyle cellStyle2 = workbook.createCellStyle();
// Cell data format
cellStyle2.setDataFormat(workbook.createDataFormat().getFormat("0.00%"));Here is the complete code ( Unit tests can be used directly ):
@org.junit.Test
public void exportExcel() throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
// Set the font
HSSFFont font2 = workbook.createFont();
// Font height
font2.setFontHeightInPoints((short) 11);
// The font color
font2.setColor(HSSFFont.COLOR_NORMAL);
// Create styles
HSSFCellStyle cellStyle2 = workbook.createCellStyle();
cellStyle2.setFont(font2);
// Horizontal layout : In the middle
cellStyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// Vertical center
cellStyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
// Cell color
cellStyle2.setFillForegroundColor(HSSFColor.ORANGE.index);
// Fill cell colors
cellStyle2.setFillPattern((short) 1);
// Cell data format
cellStyle2.setDataFormat(workbook.createDataFormat().getFormat("0.00%"));
// data
int a = 99;
double b = 101;
double rate = a / b;
rate = new BigDecimal(rate).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();
// Generate Excel
HSSFSheet sheet = workbook.createSheet("sheet");
HSSFRow row = sheet.createRow(0);
row.createCell(0).setCellValue(" Proportion ");
row.createCell(1).setCellValue(rate);
row.getCell(1).setCellStyle(cellStyle2);
// Output Excel
String filePath = "D://abc.xls";
FileOutputStream fout = new FileOutputStream(filePath);
workbook.write(fout);
fout.close();
}design sketch :

边栏推荐
- SSH link remote server and local display of remote graphical interface
- How does the insurance company check hypertension?
- What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
- scroll-view指定滚动元素的起始位置
- 机械观和系统观的科学思维方式各有什么特点和作用
- 2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)
- Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
- [LeetCode]404. 左叶子之和
- DBNet:具有可微分二值化的实时场景文本检测
- UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
猜你喜欢

Scroll view specifies the starting position of the scrolling element

These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products

The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list

2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
![[5g NR] UE registration process](/img/e3/f881d51fba03010de8c45ea480f3f0.png)
[5g NR] UE registration process

Notes on the core knowledge of Domain Driven Design DDD

数值法求解最优控制问题(一)——梯度法

2022-06-23 VGMP-OSPF-域间安全策略-NAT策略(更新中)

Realize PDF to picture conversion with C #

如何迁移或复制VMware虚拟机系统
随机推荐
EasyExcel
Simple understanding of bubble sorting
Interface test weather API
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
【无标题】
Basic teaching of crawler code
Laravel框架 踩坑(一)
2022-06-23 VGMP-OSPF-域間安全策略-NAT策略(更新中)
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
Personally design a highly concurrent seckill system
ROS+Pytorch的联合使用示例(语义分割)
Pytest -- write and manage test cases
Abstract learning
Floating menu operation
[classes and objects] explain classes and objects in simple terms
DNS forward query:
How matlab modifies default settings
golang操作redis:写入、读取hash类型数据
Software testing learning - day 3
Integration test practice (1) theoretical basis