天天看點

excel寫入筆記

excel寫入筆記

import org.apache.poi.hssf.usermodel.HSSFCell;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Sheet;

public class Demo3 {

static String FILENAMEPATH = "E:\\data.xls";

public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub

HSSFWorkbook exb = new HSSFWorkbook();//定義一個新的工作簿

Sheet sheet = exb.createSheet("第一個shell頁");   //建立一個

Row row = sheet.createRow(0); //建立一個行

Cell cell = row.createCell(0); //建立一個列

cell.setCellValue(new Date()); //給單元格設值

//寫入值

row.createCell(1).setCellValue(1);

row.createCell(2).setCellValue("第一個字元串");

row.createCell(3).setCellValue(true);

row.createCell(4).setCellValue(HSSFCell.CELL_TYPE_NUMERIC);

row.createCell(5).setCellValue(false);

//row.createCell(1).setCellValue(2);

FileOutputStream fileOut = new FileOutputStream(FILENAMEPATH);  //打開檔案

exb.write(fileOut); //寫入檔案

fileOut.close(); // 關閉檔案

System.out.println("操作成功");

}

本文轉自 知止内明 51CTO部落格,原文連結:http://blog.51cto.com/357712148/1982898,如需轉載請自行聯系原作者