java开发导出Excel

本文介绍如何使用Java POI库创建包含不同单元格类型的Excel文件。通过实例演示了设置各种单元格类型的方法,包括空白、布尔值、错误、日期、数值和字符串等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我使用的是poi3.9开发jar

dom4j

   XSSFWorkbook workbook = new XSSFWorkbook();
           XSSFSheet spreadsheet = workbook.createSheet("cell types");
           XSSFRow row = spreadsheet.createRow((short) 1);
           row.createCell(0).setCellValue("Type of Cell");
           row.createCell(1).setCellValue("cell value");
           row.createCell(2).setCellValue("你一个是实打实的");
           row=spreadsheet.createRow(10);
           row.createCell(0).setCellValue("Type of Cell");
           row.createCell(1).setCellValue("cell valsssssssue");
           row.createCell(2).setCellValue("你一个是实打实的");
           row = spreadsheet.createRow((short) 3);
           row.createCell(0).setCellValue("set cell type BLANK");
           row.createCell(1);
           row = spreadsheet.createRow((short) 4);
           row.createCell(0).setCellValue("set cell type BOOLEAN");
           row.createCell(1).setCellValue(true);
           row = spreadsheet.createRow((short) 5);
           row.createCell(0).setCellValue("set cell type ERROR");
           row.createCell(1).setCellValue(XSSFCell.CELL_TYPE_ERROR );
           row = spreadsheet.createRow((short) 6);
           row.createCell(0).setCellValue("set cell type date");
           row.createCell(1).setCellValue(new Date());
           row = spreadsheet.createRow((short) 7);
           row.createCell(0).setCellValue("set cell type numeric" );
           row.createCell(1).setCellValue(20 );
           row = spreadsheet.createRow((short) 8);
           row.createCell(0).setCellValue("set cell type string");
           row.createCell(1).setCellValue("A String");
             FileOutputStream out = new FileOutputStream(new File("my.xlsx"));
           workbook.write(out);
           out.close();
           System.out.println(
           "typesofcells.xlsx written successfully");
       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值