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(“操作成功”);
}
}
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/tech/opensource/193899.html