当前位置:网站首页>Add data to excel small and medium-sized cases through poi
Add data to excel small and medium-sized cases through poi
2022-07-05 19:33:00 【lang20150928】
At present poi The version is
<poi.veriosn>4.1.2</poi.veriosn>
Related dependencies
<!-- 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>
Case code
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);
}
// First create an empty 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++) {
// Create according to the specified flow 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);
}
}
}
}
The results are shown below ( hinder Hello World Are added by appending )
边栏推荐
- Zhongang Mining: analysis of the current market supply situation of the global fluorite industry in 2022
- XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
- 成功入职百度月薪35K,2022Android开发面试解答
- The city chain technology Digital Innovation Strategy Summit was successfully held
- What does software testing do? What are the requirements for learning?
- 建议收藏,我的腾讯Android面试经历分享
- Debezium系列之:IDEA集成词法和语法分析ANTLR,查看debezium支持的ddl、dml等语句
- 【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
- acm入门day1
- JAD installation, configuration and integration idea
猜你喜欢
如何实现游戏中的在线计时器和离线计时器
Fuzor 2020軟件安裝包下載及安裝教程
How to convert word into PDF? Word to PDF simple way to share!
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
司空见惯 - 英雄扫雷鼠
Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
aggregate
How to realize the Online timer and offline timer in the game
强化学习-学习笔记4 | Actor-Critic
How to apply smart contracts more wisely in 2022?
随机推荐
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
Fuzor 2020 software installation package download and installation tutorial
太牛了,看这篇足矣了
【AI 框架基础技术】自动求导机制 (Autograd)
出海十年:新旧接力,黑马崛起
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
PG基础篇--逻辑结构管理(用户及权限管理)
100million single men and women supported an IPO with a valuation of 13billion
Debezium系列之:解析默认值字符集
Go语言学习教程(十五)
PG basics -- Logical Structure Management (user and permission management)
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
C application interface development foundation - form control (5) - grouping control
C# 语言的高级应用
软件测试是干什么的?学习有啥要求?
城链科技数字化创新战略峰会圆满召开
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
从零实现深度学习框架——LSTM从理论到实战【实战】
Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
word如何转换成pdf?word转pdf简单的方法分享!