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

边栏推荐
- golang操作redis:写入、读取kv数据
- Golang operation redis: write and read hash type data
- 保险公司怎么查高血压?
- IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
- Interface learning
- [untitled]
- DNS forward query:
- [Code] if (list! = null & list. Size() > 0) optimization, set empty judgment implementation method
- Golang operation redis: write and read kV data
猜你喜欢

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

Pytest -- write and manage test cases

SSH link remote server and local display of remote graphical interface

MySQL installation

EasyExcel

Winter vacation work of software engineering practice

ROS+Pytorch的联合使用示例(语义分割)

Summary of the design and implementation of the weapon system similar to the paladin of vitality

Reading notes of "learn to ask questions"

(翻译)异步编程:Async/Await在ASP.NET中的介绍
随机推荐
Unit test framework + Test Suite
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-域间安全策略-NAT策略(更新中)
mysql误删root账户导致无法登录
The difference between CONDA and pip
centos php7.2.24升级到php7.3
Ruoyi interface permission verification
New knowledge! The virtual machine network card causes your DNS resolution to slow down
机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
Derivation of variance iteration formula
【类和对象】深入浅出类和对象
opencv
Summary of remote connection of MySQL
Software testing learning - day 3
Interface test weather API
每日刷題記錄 (十一)
Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
pytorch练习小项目
利用C#实现Pdf转图片
Know flex box