1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class ExcelWrite { private static String PATH = "/Users/panyurou/IdeaProjects/exceldemo";
@Test public void excelWrite() throws IOException { Workbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("测试excel写入"); Row row1 = sheet.createRow(0); Cell cell11 = row1.createCell(0); cell11.setCellValue("我是单元格(1,1)");
Row row2 = sheet.createRow(1); Cell cell21 = row2.createCell(0); String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss"); cell21.setCellValue(time);
FileOutputStream outputStream = new FileOutputStream(PATH + "/excel写入.xlsx"); workbook.write(outputStream); outputStream.close(); System.out.println("excel 写入完毕!"); } }
|