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("操作成功");
}
}
excel寫入筆記