码迷,mamicode.com
首页 > 其他好文 > 详细

POI导出高版本Excel——(五)

时间:2017-08-02 10:06:21      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:csv   gms   xdg   dal   nmp   hds   fpm   pack   roo   

 1 package POI;
 2 
 3 import java.io.File;
 4 import java.io.FileOutputStream;
 5 import java.io.IOException;
 6 
 7 import org.apache.commons.io.FileUtils;
 8 import org.apache.poi.ss.usermodel.Cell;
 9 import org.apache.poi.ss.usermodel.Row;
10 import org.apache.poi.ss.usermodel.Sheet;
11 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
12 
13 
14 
15 public class POIHeighVersion {
16     public static void main(String[] args) {
17         String[] title = {"id","name","sex"};
18 //        创建一个工作簿
19         XSSFWorkbook workbook = new XSSFWorkbook();
20 //        创建一个工作表sheet
21         Sheet sheet = workbook.createSheet();
22 //        创建第一行
23         Row row = sheet.createRow(0);
24 //        创建一个单元格
25         Cell cell = null;
26 //        创建表头
27         for(int i=0;i<title.length;i++){
28             cell=row.createCell(i);
29             cell.setCellValue(title[i]);
30         }
31 //        从第二行开始追加数据
32         for(int i=1;i<=10;i++){
33 //            创建第i行
34             Row nextRow = sheet.createRow(i);
35 //            参数代表第几列
36             Cell cell2 = nextRow.createCell(0);
37             cell2.setCellValue("a"+i);
38             cell2 = nextRow.createCell(1);
39             cell2.setCellValue("user"+i);
40             cell2 = nextRow.createCell(2);
41             cell2.setCellValue("男");
42         }
43 //        创建一个文件
44         File file = new File("E:/POI_TEST.xlsx");
45         try {
46             file.createNewFile();
47 //            打开文件流
48             FileOutputStream outputStream = FileUtils.openOutputStream(file);
49             workbook.write(outputStream);
50             outputStream.close();
51         } catch (IOException e) {
52             // TODO Auto-generated catch block
53             e.printStackTrace();
54         }
55         
56     }
57     
58 }

结果 :

技术分享

POI导出高版本Excel——(五)

标签:csv   gms   xdg   dal   nmp   hds   fpm   pack   roo   

原文地址:http://www.cnblogs.com/qlqwjy/p/7271642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!