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

边栏推荐
- vmware虚拟机C盘扩容
- 【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
- The essence of interview
- IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
- 2022年华东师范大学计科考研复试机试题-详细题解
- DNS forward query:
- centos php7.3安装redis扩展
- These two mosquito repellent ingredients are harmful to babies. Families with babies should pay attention to choosing mosquito repellent products
- Create your own deep learning environment with CONDA
- 10000小時定律不會讓你成為編程大師,但至少是個好的起點
猜你喜欢

2022 CISP-PTE(三)命令执行

scroll-view指定滚动元素的起始位置

Yolov3 learning notes

Create your own deep learning environment with CONDA

2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)

(翻译)异步编程:Async/Await在ASP.NET中的介绍

Yolov1 learning notes

Personally design a highly concurrent seckill system

My 2020 summary "don't love the past, indulge in moving forward"

100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
随机推荐
Software testing assignment - day 3
Basic teaching of crawler code
【无标题】
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
Integration test practice (1) theoretical basis
多个全局异常处理类,怎么规定执行顺序
2022 CISP-PTE(三)命令执行
How does the insurance company check hypertension?
【code】if (list != null && list.size() > 0)优化,集合判空实现方式
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
10000小时定律不会让你成为编程大师,但至少是个好的起点
Software testing learning - the next day
机械观和系统观的科学思维方式各有什么特点和作用
php artisan
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Interface test weather API
Numerical method for solving optimal control problem (I) -- gradient method
Yolov3 learning notes
ROS+Pytorch的联合使用示例(语义分割)
[C /vb.net] convert PDF to svg/image, svg/image to PDF