当前位置:网站首页>通过POI追加数据到excel中小案例
通过POI追加数据到excel中小案例
2022-07-05 19:12:00 【lang20150928】
当前poi的版本为
<poi.veriosn>4.1.2</poi.veriosn>
相关依赖
<!-- apache POI for xls -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.veriosn}</version>
</dependency>
<!-- apache POI for xlsx -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.veriosn}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.veriosn}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.veriosn}</version>
</dependency>
案例代码
public static void main(String[] args) throws IOException {
String fileName = "D:\\data\\excel\\workbook.xls";
File file = new File(fileName);
if (file.exists()) {
FileUtils.forceDelete(file);
}
// 首先创建一个空的excel
try (Workbook wb = WorkbookFactory.create(false)) {
Sheet wbSheet = wb.createSheet();
Row row = wbSheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("First Row");
try (FileOutputStream fileOut = new FileOutputStream(fileName)) {
wb.write(fileOut);
}
}
for (int i = 0; i < 10; i++) {
// 根据指定的流创建excel
try (Workbook wb = WorkbookFactory.create(new FileInputStream(fileName))) {
Sheet wbSheet = wb.getSheetAt(0);
Row row = wbSheet.createRow(i + 1);
Cell cell = row.createCell(i);
cell.setCellValue("Hello World!" + i);
try (FileOutputStream fileOut = new FileOutputStream(fileName)) {
wb.write(fileOut);
}
}
}
}
结果如下所示(后面的Hello World都是通过追加的方式添加的)
边栏推荐
- JAD的安装、配置及集成IDEA
- MySql中的longtext字段的返回问题及解决
- Applet modification style (placeholder, checkbox style)
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- 中国银河证券开户安全吗 证券开户
- 【历史上的今天】7 月 5 日:Google 之母出生;同一天诞生的两位图灵奖先驱
- After the company went bankrupt, the blackstones came
- Talking about fake demand from takeout order
- Tianyi cloud understands enterprise level data security in this way
- 14、用户、组和权限(14)
猜你喜欢

如何在2022年更明智地应用智能合约?

公司破产后,黑石们来了

Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法

软件测试是干什么的?学习有啥要求?

基于FPGA的超声波测距

Advanced application of C # language

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

Go deep into the underlying C source code and explain the core design principles of redis
![[AI framework basic technology] automatic derivation mechanism (autograd)](/img/9c/a5713def131dc7643cc19b3839ff0c.png)
[AI framework basic technology] automatic derivation mechanism (autograd)

全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
随机推荐
强化学习-学习笔记4 | Actor-Critic
2022 the most complete Tencent background automation testing and continuous deployment practice in the whole network [10000 words]
5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
R language uses lubridate package to process date and time data
PHP利用ueditor实现上传图片添加水印
HAC cluster modifying administrator user password
Hiengine: comparable to the local cloud native memory database engine
Technology sharing | interface testing value and system
Which securities company is better and which platform is safer for mobile account opening
Summer Challenge database Xueba notes, quick review of exams / interviews~
JS解力扣每日一题(十二)——556. 下一个更大元素 III(2022-7-3)
PHP uses ueditor to upload pictures and add watermarks
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
司空见惯 - 英雄扫雷鼠
ELK分布式日志分析系统部署(华为云)
Go语言 | 03 数组、指针、切片用法
Pandora IOT development board learning (HAL Library) - Experiment 8 timer interrupt experiment (learning notes)
Oracle fault handling: ora-10873:file * needs to be either taken out of backup or media recovered
软件测试是干什么的?学习有啥要求?
MMO項目學習一:預熱