欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Demo POI 博客分类: JavaPOI excelJavaPOI 

程序员文章站 2024-03-24 10:20:40
...
import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class book
{
    public static void main(String[] args) throws Exception
    {
        //HSSFWorkbook
        
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet hssfSheet =  wb.createSheet("Excel Template");
        Row row = hssfSheet.createRow(0);
        Cell cell1 = row.createCell(0);
        cell1.setCellType(Cell.CELL_TYPE_STRING);
        cell1.setCellValue("HSSFWorkbook");
        
        FileOutputStream out = new FileOutputStream(args[0]+"HSSFWorkbook.xls");
        wb.write(out);
        out.flush();
        out.close();
        
        
        //
       
        SXSSFWorkbook hwb = new SXSSFWorkbook(1000);
        hwb.setCompressTempFiles(true);
        SXSSFSheet sheet  = (SXSSFSheet) hwb.createSheet("Excel Template");
        SXSSFRow rowhead = (SXSSFRow) sheet.createRow(0);
        
        Cell xssfCell = rowhead.createCell(0);
        xssfCell.setCellType(Cell.CELL_TYPE_STRING);
        xssfCell.setCellValue("SXSSFWorkbook");
        FileOutputStream fileOut = new FileOutputStream(args[0]+"SXSSFWorkbook.xlsx");
        hwb.write(fileOut);
        fileOut.flush();
        fileOut.close();
        
        
        
        Workbook hwb1 = new XSSFWorkbook();
        XSSFSheet xssfsheet = (XSSFSheet) hwb1.createSheet("Excel Template");
        Row r = xssfsheet.createRow(0);
        Cell ce = r.createCell(0);
        ce.setCellType(Cell.CELL_TYPE_STRING);
        ce.setCellValue("XSSFWorkbook");
        FileOutputStream fileOut1 = new FileOutputStream(args[0]+"XSSFWorkbook.xlsx");
        hwb1.write(fileOut1);
        fileOut1.flush();
        fileOut1.close();
    }
}

 

相关标签: excel Java POI