java 写入/读取 excel

本篇以EXCEL 2007 以上版本为例:

一、依赖

  1.  2007以上版本artifactId为poi-ooxml,2007以下版本是poi就可以了!

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>

2.写入Excel
  
Workbook wk = new XSSFWorkbook();            //一个Excel对象
Sheet sheet=wk.createSheet("sheet4");     //创建sheet
Row headrow = sheet.createRow(0);        //创建行
Cell cell = headrow.createCell(0); //创建单元格
cell.setValue("猪八戒"); //插入值
FileOutputStream s = new FileOutputStream("D:\\test.xlsx"); //创建流
wk.write(s); //将wk持久化到EXCEL

3读取excel
1.先创建流
2.其他跟写入差不多



posted @ 2018-08-06 22:33  王戈戈戈戈戈戈  阅读(157)  评论(0编辑  收藏  举报