当前位置:网站首页>通过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都是通过追加的方式添加的)
边栏推荐
- MySQL中字段类型为longtext的值导出后显示二进制串方式
- HAC集群修改管理员用户密码
- 信息/数据
- 集合
- You can have both fish and bear's paw! Sky wing cloud elastic bare metal is attractive!
- 5 years of experience, 27 days of Android programmer interview, 2022 programmer advanced classic
- MySql中的longtext字段的返回问题及解决
- #夏日挑战赛# HarmonyOS - 实现消息通知功能
- Millimeter wave radar human body sensor, intelligent perception of static presence, human presence detection application
- MMO project learning 1: preheating
猜你喜欢

Reflection and imagination on the notation like tool

Benefits of automated testing

全网最全的低代码/无代码平台盘点:简道云、伙伴云、明道云、轻流、速融云、集简云、Treelab、钉钉·宜搭、腾讯云·微搭、智能云·爱速搭、百数云
![CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]](/img/5d/06229ff7cfa144dbcb60ae43d5c435.png)
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]

Tianyi cloud understands enterprise level data security in this way

强化学习-学习笔记4 | Actor-Critic

ELK分布式日志分析系统部署(华为云)
PHP利用ueditor实现上传图片添加水印

JAD的安装、配置及集成IDEA

JMeter 常用的几种断言方法,你会了吗?
随机推荐
Summer Challenge database Xueba notes, quick review of exams / interviews~
Teach you to deal with JS reverse picture camouflage hand in hand
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
The problem of returning the longtext field in MySQL and its solution
Common interview questions in Android, 2022 golden nine silver ten Android factory interview questions hit
cf:B. Almost Ternary Matrix【對稱 + 找規律 + 構造 + 我是構造垃圾】
微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
How to convert word into PDF? Word to PDF simple way to share!
Debezium系列之:postgresql从偏移量加载正确的最后一次提交 LSN
Go语言学习教程(十六)
What are the reliable domestic low code development platforms?
R语言可视化散点图(scatter plot)图、为图中的部分数据点添加标签、始终显示所有标签,即使它们有太多重叠、ggrepel包来帮忙
从零实现深度学习框架——LSTM从理论到实战【实战】
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
Android interview, Android audio and video development
HiEngine:可媲美本地的云原生内存数据库引擎
Is it safe for Guohai Securities to open an account online?