如何使用Java POI生成Excel表文件

2024-12-17 06:09:23
推荐回答(1个)
回答1:

1234567891011121314151617181920212223242526272829       private static void WriteExcel2010() throws IOException {        String path="C:\\poi2.xlsx";        XSSFWorkbook workbook=new XSSFWorkbook();        XSSFSheet sheet=workbook.createSheet("我的Sheet");         XSSFRow row=sheet.createRow(0);        XSSFCell cell=row.createCell(0);        cell.setCellValue("我是POI写入的");         XSSFRow row1=sheet.createRow(1);        XSSFCell cell1=row1.createCell(0);        cell1.setCellValue("2010");         FileOutputStream outputStream=new FileOutputStream(path);        workbook.write(outputStream);        outputStream.close();    }     private static void WriteExcel2003() throws IOException {        String path="C:\\poi2.xls";        HSSFWorkbook workbook=new HSSFWorkbook();        HSSFSheet sheet=workbook.createSheet("我的Excel");        HSSFRow row=sheet.createRow(0);        HSSFCell cell=row.createCell(0);        cell.setCellValue("我是POI写入的");        FileOutputStream outputStream=new FileOutputStream(path);        workbook.write(outputStream);        outputStream.close();    }