当前位置:网站首页>POI add write excel file
POI add write excel file
2022-07-06 08:38:00 【renkai721】
Requirement scenario description :
Sometimes we need to upload a complete EXCEL Split into several different EXCEL, Then send it to people in different departments to deal with it , And then put these EXCEL Merge into one EXCEL In file .
The address of the following article is EXCEL2003 To deal with , If it is 2007 Versions above need to be modified manually HSSF by XSSF That's all right. .
POI:EXCEL Export and append - Visit the garden and recall - Blog Garden
Here is poi Code snippets processed
1、pom Add to file poi rely on
<!-- poi start -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.1.2</version>
</dependency>
2、 Additional writing EXCEL Core code .
public void appendExcel(String saveOrderLocalPath, int beginRow, List<SubmitYhdDecomposeExcel> list) throws IOException {
FileOutputStream out = null;
log.info("saveOrderLocalPath={},beginRow={}",saveOrderLocalPath,beginRow);
FileInputStream fileInputStream = new FileInputStream(saveOrderLocalPath);
XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFCellStyle cellStyle = workbook.createCellStyle();
// ----------------- Additional data -------------------
if(beginRow > 1){
// Which line should I start with , Pay attention to what is passed here beginRow yes EXCEL Real lines , Row number
// The code needs to judge that it is greater than 1 When you go, you need to subtract the subscript 1, The program is written from 0 At the beginning .
// Because there is a header , therefore beginRow=1 There is no reduction here 1
beginRow -= 1;
}
for (int i = 0; i < list.size(); i++) {
SubmitYhdDecomposeExcel rowObj = list.get(i);
XSSFRow startRow = sheet.createRow(i + beginRow);
for (int col = 0; col < 18; col++) {
XSSFCell cell = startRow.createCell(col);
switch (col) {
case 0:
cell.setCellValue(rowObj.getCus_no());
break;
case 1:
cell.setCellValue(rowObj.getType());
break;
case 2:
cell.setCellValue(rowObj.getNum());
break;
case 3:
cell.setCellValue(rowObj.getPrice_input());
break;
case 4:
cell.setCellValue(rowObj.getNormal_type());
break;
case 5:
cell.setCellValue(rowObj.getBak());
break;
case 6:
cell.setCellValue(rowObj.getUnfit());
break;
case 7:
cell.setCellValue(rowObj.getPack());
break;
case 8:
cell.setCellValue(rowObj.getOne_price());
break;
case 9:
cell.setCellValue(rowObj.getLow_price());
break;
case 10:
cell.setCellValue(rowObj.getDate());
break;
case 11:
cell.setCellValue(rowObj.getCheap_type());
break;
case 12:
cell.setCellValue(rowObj.getCheap_bak());
break;
case 13:
cell.setCellValue(rowObj.getCheap_unfit());
break;
case 14:
cell.setCellValue(rowObj.getCheap_pack());
break;
case 15:
cell.setCellValue(rowObj.getCheap_one_price());
break;
case 16:
cell.setCellValue(rowObj.getCheap_low_price());
break;
case 17:
cell.setCellValue(rowObj.getCheap_date());
break;
default:
break;
}
cell.setCellStyle(cellStyle);
}
}
// Output Excel file
out = new FileOutputStream(saveOrderLocalPath);
workbook.write(out);
out.flush();
out.close();
fileInputStream.close();
log.info(" Append write EXCEL complete .");
}
边栏推荐
- IoT -- 解读物联网四层架构
- FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
- 游戏解包的危害及资源加密的重要性
- JS inheritance method
- gcc动态库fPIC和fpic编译选项差异介绍
- pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
- MySQL learning record 10getting started with JDBC
- Unified ordering background interface product description Chinese garbled
- China polyether amine Market Forecast and investment strategy report (2022 Edition)
- 电脑清理,删除的系统文件
猜你喜欢
Image, CV2 read the conversion and size resize change of numpy array of pictures
PC easy to use essential software (used)
【MySQL】锁
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
pytorch训练好的模型在加载和保存过程中的问题
Leetcode question brushing (5.28) hash table
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Sort according to a number in a string in a column of CSV file
企微服务商平台收费接口对接教程
2022.02.13 - NC001. Reverse linked list
随机推荐
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
Purpose of computer F1-F12
C语言双指针——经典题型
leetcode刷题 (5.29) 哈希表
The harm of game unpacking and the importance of resource encryption
JS pure function
软件卸载时遇到trying to use is on a network resource that is unavailable
【MySQL】日志
marathon-envs项目环境配置(强化学习模仿参考动作)
visdom可视化实现与检查介绍
China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
Beijing invitation media
Chrome浏览器的crash问题
Sort according to a number in a string in a column of CSV file
Problems in loading and saving pytorch trained models
egg. JS getting started navigation: installation, use and learning
Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
【ROS】usb_ Cam camera calibration
Roguelike游戏成破解重灾区,如何破局?
Bitwise logical operator