简单的一个记录,主要记录通过poi进行读写excel的操作,
目前常见读写Excel的工具类开源javaAPI有两种方式。
一个是JXL(Java Excel API) 官网地址:http://jexcelapi.sourceforge.net/
一个是Apache的POI(Poor Obfuscation Implementation)官网地址:http://poi.apache.org/
环境配置
官网下载稳定版,在http://poi.apache.org/download.html 可看到最新稳定版,在跳转页下载poi-bin-version-YMD.zip
解压后可见如下目录,
读写excel所需jar包基本如下,在idea中导入jar包方式为File –> Project Structure –>Modules->Dependencies,点击+号即可添加,添加后就是下图的显示
查看文档
可以在官方找到当前版本的文档,http://poi.apache.org/apidocs/index.html
相关代码:
简单的小例子
public class Main {
public static void main(String[] args) {
//web对象
XSSFWorkbook wb = new XSSFWorkbook();
//创建表头等
XSSFSheet sheet = wb.createSheet("test1");
for (int i = 0; i < 5; i++) {
//创建行
XSSFRow row = sheet.createRow(i);
//创建列
XSSFCell cell = row.createCell(i);
cell.setCellValue("值");
}
try {
FileOutputStream output = new FileOutputStream("g:\\1.xlsx");
wb.write(output);
output.flush();
System.out.println("成功创建excel文件");
} catch (Exception e) {
e.printStackTrace();
}
}
}
入门小白,感谢分享,建议加点示例代码会更充实一些 ::twemoji:smile::
不错不错,感谢 ::twemoji:smile::