当前位置:网站首页>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 .");
}
边栏推荐
- Synchronized solves problems caused by sharing
- logback1.3. X configuration details and Practice
- Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
- IoT -- 解读物联网四层架构
- 企微服务商平台收费接口对接教程
- 延迟初始化和密封类
- Screenshot in win10 system, win+prtsc save location
- vulnhub hackme: 1
- ROS编译 调用第三方动态库(xxx.so)
- C語言雙指針——經典題型
猜你喜欢
Indentation of tabs and spaces when writing programs for sublime text
Cisp-pte practice explanation
On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced
Light of domestic games destroyed by cracking
Pointer advanced --- pointer array, array pointer
vulnhub hackme: 1
被破解毁掉的国产游戏之光
Chrome浏览器的crash问题
C語言雙指針——經典題型
IoT -- 解读物联网四层架构
随机推荐
同一局域网的手机和电脑相互访问,IIS设置
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
Indentation of tabs and spaces when writing programs for sublime text
IOT -- interpreting the four tier architecture of the Internet of things
FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
延迟初始化和密封类
【ROS】usb_ Cam camera calibration
C language double pointer -- classic question type
Ruffian Heng embedded bimonthly, issue 49
被破解毁掉的国产游戏之光
Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
Pointer advanced --- pointer array, array pointer
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
企微服务商平台收费接口对接教程
vulnhub hackme: 1
Sublime text using ctrl+b to run another program without closing other runs
[2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
电脑F1-F12用途
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
【Nvidia开发板】常见问题集 (不定时更新)