java poi之Excel的创建
生活随笔
收集整理的這篇文章主要介紹了
java poi之Excel的创建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
poi之Excel的創建
package com.imooc.excel;import java.io.File; import java.io.FileOutputStream;import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook;public class Poi_Exp_Excel { /*** POI生成Excel文件* @param args*/public static void main(String[] args) {String[] title={"id","name","sex"};//創建一個工作簿HSSFWorkbook workbook=new HSSFWorkbook();//創建一個sheetHSSFSheet sheet=workbook.createSheet();//創建第一行HSSFRow row=sheet.createRow(0);HSSFCell cell=null;//插入第一行數據 id name sexfor (int i = 0; i < title.length; i++) {cell=row.createCell((short) i);cell.setCellValue(title[i]);}//追加數據for (int i = 1; i < 10; i++) {HSSFRow nextrows=sheet.createRow(i);HSSFCell cell2=nextrows.createCell((short) 0);cell2.setCellValue("a"+i); cell2=nextrows.createCell((short)1);cell2.setCellValue("user"+i);cell2=nextrows.createCell((short)2);cell2.setCellValue("男"+i); }//創建一個文件File file=new File("D:/jxl_poi_text.xls");try {file.createNewFile();//將Excel內容存盤FileOutputStream stream =new FileOutputStream(file);workbook.write(stream);stream.close();} catch (Exception e) {// TODO: handle exception}} }總結
以上是生活随笔為你收集整理的java poi之Excel的创建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 书籍推荐词28句
- 下一篇: java poi之Excel的读取