当前位置:网站首页>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 :

边栏推荐
- 2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
- 【5G NR】UE注册流程
- ROS+Pytorch的联合使用示例(语义分割)
- 10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
- Arctic code vault contributor
- EasyExcel
- Paper notes vsalm literature review "a comprehensive survey of visual slam algorithms"
- 这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
- 第8章、MapReduce 生产经验
- Software testing learning - day 3
猜你喜欢

Practice of enterprise ab/testing platform

Ruoyi interface permission verification

每日刷题记录 (十一)

Winter vacation work of software engineering practice
![[classes and objects] explain classes and objects in simple terms](/img/41/250457530880dfe3728432c2ccd50b.png)
[classes and objects] explain classes and objects in simple terms

The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?

Chapter 8. MapReduce production experience

Example of joint use of ros+pytoch (semantic segmentation)

【无标题】
![[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle](/img/f8/0e3fbfd13bf06291a73200552ff17a.png)
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
随机推荐
UTC时间、GMT时间、CST时间
Arctic code vault contributor
The dynamic analysis and calculation of expressions are really delicious for flee
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
Yolov3 learning notes
如何迁移或复制VMware虚拟机系统
Selenium - by changing the window size, the width, height and length of different models will be different
Example of joint use of ros+pytoch (semantic segmentation)
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
golang操作redis:写入、读取hash类型数据
机械观和系统观的科学思维方式各有什么特点和作用
centos php7.2.24升级到php7.3
[C /vb.net] convert PDF to svg/image, svg/image to PDF
SQL implementation merges multiple rows of records into one row
Abstract learning
Software testing learning - day one
[untitled] 8 simplified address book
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
利用C#实现Pdf转图片
instanceof