1.poi 读写excel
来源:互联网 发布:淘宝分销平台能挣钱吗 编辑:程序博客网 时间:2024/06/15 15:40
1.准备eclipse
2.配置maven
3.导入poi的jar包
pom文件添加
<!-- 操作excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
</dependencies>
源码如下:
package test.pom.api;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class Test {
public static void main(String[] args) {
System.out.println("111");
String excelPath = "C:/Users/yvon/Desktop/1.xlsx";
FileOutputStream fos = null;
try {
fos = new FileOutputStream(excelPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 创建一个工作簿
Workbook wb = new HSSFWorkbook();
// 创建sheet页
Sheet Sheet1 = wb.createSheet("三年级(1)班学生名单");
/* Sheet Sheet2 = wb.createSheet("三年级(2)班学生名单"); */
/* Sheet Sheet3 = wb.createSheet("三年级(3)班学生名单"); */
// 使用Sheet创建行
Row Row1 = Sheet1.createRow(0);
/*
* Cell c1 = Row1.createCell(0); c1.setCellValue(6);
*
* Cell c2 = Row1.createCell(1); c2.setCellValue(1.2);
*
* Cell c3 = Row1.createCell(2); c3.setCellValue("我爱宝宝金!!!");
*/
for (int i = 0; i < 10; i++) {
Cell c3 = Row1.createCell(i);
c3.setCellValue("我爱宝宝金!!!");
}
try {
// 写出到目标文件
wb.write(fos);
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getWorkbook();
}
public static void getWorkbook() {
String excelPath = "C:/Users/yvon/Desktop/1.xlsx";
FileInputStream fis = null;
POIFSFileSystem fs = null;
Workbook wb1 = null;
try {
fis = new FileInputStream(excelPath);
// 将文件流解析成 POI 文档
fs = new POIFSFileSystem(fis);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
wb1 = new HSSFWorkbook(fs);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*
* Sheet Sheet2 = wb1.createSheet("三年级(2)班学生名单"); Row Row1 =
* Sheet2.createRow(0);
*/
Sheet Sheet2 = wb1.getSheet("三年级(1)班学生名单");
Row Row1 = Sheet2.getRow(0);
for (int i = 0; i < 10; i++) {
Cell c3 = Row1.getCell(i);
// c3.setCellValue("我爱宝宝金!!!");
System.out.println(c3.getStringCellValue());
}
try {
fis.close();
wb1.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- 1.poi 读写excel
- POI读写Excel文件
- POI读写Excel文件
- POI读写Excel文件
- POI读写Excel文件
- POI读写Excel文件
- POI读写Excel
- POI读写excel文件
- poi读写excel
- poi读写 excel
- Java读写Excel-POI
- 用POI读写Excel
- POI简单读写excel
- POI 读写Excel 范例
- poi读写Excel文件
- POI读写EXCEL
- POI读写海量Excel
- POI 读写 Excel
- HDU4738 Caocao's Bridges【强连通】
- 企慧Q5快速开发平台系列之四:“零”代码理念
- Apache Kafka:下一代分布式消息系统
- Spring4下validation数据校验无效(maven)
- eclipse中配置python解释器
- 1.poi 读写excel
- 【牛腩】-总结
- hdu--6127--Hard challenge
- Python切片
- TP5中的第三方类解释
- spring boot Junit单元测试
- 数据结构:哈希表
- AWS
- hive对电商用户订单行为特征分析(二)