poi 创建excel表格->简单实现
来源:互联网 发布:中国出口构成 知乎 编辑:程序博客网 时间:2024/05/22 03:14
import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.openxml4j.exceptions.InvalidFormatException;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;public class excelWrite { public static void main(String[] args) throws IOException, InvalidFormatException { //创建路径 File testFile = new File("/Users/liuxiangru/Desktop/testa.xlsx"); //创建输出流 FileOutputStream fileOutputStream = new FileOutputStream(testFile); //创建工作薄 HSSFWorkbook xssfWorkbook=new HSSFWorkbook(); //创建Sheet页->创建Row->创建cell->填写单元格内容 xssfWorkbook.createSheet("one") .createRow(0).createCell(0) .setCellValue("age=18"); //把excel工作簿写入硬盘 xssfWorkbook.write(fileOutputStream); fileOutputStream.flush(); fileOutputStream.close(); }}
阅读全文