As an example, you can try this snippet:
protected void buildExcelDocument( Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) { // Go to the first sheet. // getSheetAt: only if workbook is created from an existing document // HSSFSheet sheet = workbook.getSheetAt(0); HSSFSheet sheet = workbook.createSheet("Spring"); sheet.setDefaultColumnWidth(12); // Write a text at A1. HSSFCell cell = getCell(sheet, 0, 0); setText(cell, "Spring POI test"); // Write the current date at A2. HSSFCellStyle dateStyle = workbook.createCellStyle(); dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); cell = getCell(sheet, 1, 0); cell.setCellValue(new Date()); cell.setCellStyle(dateStyle); // Write a number at A3 getCell(sheet, 2, 0).setCellValue(458); // Write a range of numbers. HSSFRow sheetRow = sheet.createRow(3); for (short i = 0; i < 10; i++) { sheetRow.createCell(i).setCellValue(i * 10); } }This class is similar to the AbstractPdfView class in usage style. @author Jean-Pierre Pawlak @author Juergen Hoeller @see AbstractPdfView
|
|