diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/DummyDataGenerator.java b/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/DummyDataGenerator.java deleted file mode 100644 index f9a4bb4d776acd167f0c23a441c35274b90a79bd..0000000000000000000000000000000000000000 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/DummyDataGenerator.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.springside.examples.showcase.utilities.excel; - -/** - * 报表演示的模拟数据提供类. - * - * @author calvin - */ -public class DummyDataGenerator { - - public static TemperatureAnomaly[] getDummyData() { - - return new TemperatureAnomaly[] { new TemperatureAnomaly(1970, -0.068, -0.108), - new TemperatureAnomaly(1971, -0.190, -0.104), new TemperatureAnomaly(1972, -0.056, -0.100), - new TemperatureAnomaly(1973, 0.077, -0.097), new TemperatureAnomaly(1974, -0.213, -0.091), - new TemperatureAnomaly(1975, -0.170, -0.082), new TemperatureAnomaly(1976, -0.254, -0.068), - new TemperatureAnomaly(1977, 0.019, -0.050), new TemperatureAnomaly(1978, -0.063, -0.028), - new TemperatureAnomaly(1979, 0.050, -0.006), new TemperatureAnomaly(1980, 0.077, 0.015), - new TemperatureAnomaly(1981, 0.120, 0.032), new TemperatureAnomaly(1982, 0.011, 0.046), - new TemperatureAnomaly(1983, 0.177, 0.058), new TemperatureAnomaly(1984, -0.021, 0.069), - new TemperatureAnomaly(1985, -0.037, 0.081), new TemperatureAnomaly(1986, 0.030, 0.094), - new TemperatureAnomaly(1987, 0.179, 0.108), new TemperatureAnomaly(1988, 0.180, 0.123), - new TemperatureAnomaly(1989, 0.104, 0.137), new TemperatureAnomaly(1990, 0.255, 0.150), - new TemperatureAnomaly(1991, 0.210, 0.163), new TemperatureAnomaly(1992, 0.065, 0.178), - new TemperatureAnomaly(1993, 0.110, 0.195), new TemperatureAnomaly(1994, 0.172, 0.216), - new TemperatureAnomaly(1995, 0.269, 0.241), new TemperatureAnomaly(1996, 0.141, 0.268), - new TemperatureAnomaly(1997, 0.353, 0.296), new TemperatureAnomaly(1998, 0.548, 0.323), - new TemperatureAnomaly(1999, 0.298, 0.348) }; - } - - /** - * 年度气温记录类. - * - * @author calvin - */ - public static class TemperatureAnomaly { - private int year; - private double anomaly; - private double smoothed; - - public TemperatureAnomaly(int year, double anomaly, double smoothed) { - this.year = year; - this.anomaly = anomaly; - this.smoothed = smoothed; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - - public double getAnomaly() { - return anomaly; - } - - public void setAnomaly(double anomaly) { - this.anomaly = anomaly; - } - - public double getSmoothed() { - return smoothed; - } - - public void setSmoothed(double smoothed) { - this.smoothed = smoothed; - } - } -} diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/ExcelExportController.java b/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/ExcelExportController.java deleted file mode 100644 index 1624a8e10a582a59b3d8d2cf451d566ca5ff2950..0000000000000000000000000000000000000000 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/utilities/excel/ExcelExportController.java +++ /dev/null @@ -1,219 +0,0 @@ -package org.springside.examples.showcase.utilities.excel; - -import java.util.Map; - -import javax.servlet.http.HttpServletResponse; - -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.DataFormat; -import org.apache.poi.ss.usermodel.Font; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.joda.time.DateTime; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springside.examples.showcase.utilities.excel.DummyDataGenerator.TemperatureAnomaly; -import org.springside.modules.web.Servlets; - -import com.google.common.collect.Maps; - -/** - * 基于POI导出Excel文件的Controller. - * - * @author calvin - */ -@Controller -public class ExcelExportController { - - private Map styles; - private int rowIndex = 0; - - /** - * 生成Excel格式的内容. - */ - @RequestMapping(value = "/excel/export") - public void export(HttpServletResponse response) throws Exception { - //生成Excel文件. - Workbook wb = exportExcelWorkbook(); - - //输出Excel文件. - response.setContentType(Servlets.EXCEL_TYPE); - Servlets.setFileDownloadHeader(response, "温度年表.xls"); - - wb.write(response.getOutputStream()); - response.getOutputStream().flush(); - } - - private Workbook exportExcelWorkbook() { - TemperatureAnomaly[] temperatureAnomalyArray = DummyDataGenerator.getDummyData(); - - //创建Workbook - Workbook wb = new HSSFWorkbook(); - - //创建所有Cell Style - createStyles(wb); - - //创建工作表. - Sheet s = wb.createSheet("1970-1999"); - - //设定冻结表头 - s.createFreezePane(0, 2, 0, 2); - - //设定所有Column宽度自动配合内容宽度 - s.autoSizeColumn(0); - s.autoSizeColumn(1); - s.autoSizeColumn(2); - - //产生标题 - generateTitle(s); - //产生表头 - generateHeader(s); - //产生内容 - generateContent(s, temperatureAnomalyArray); - //产生合计 - generateTotals(s); - - return wb; - } - - private void generateTitle(Sheet s) { - Row r = s.createRow(rowIndex++); - Cell c1 = r.createCell(0); - c1.setCellValue("Temperature Anomaly(1970-1999)"); - c1.setCellStyle(styles.get("header")); - //合并单元格 - s.addMergedRegion(CellRangeAddress.valueOf("$A$1:$C$1")); - } - - private void generateHeader(Sheet s) { - - Row r = s.createRow(rowIndex++); - CellStyle headerStyle = styles.get("header"); - - Cell c1 = r.createCell(0); - c1.setCellValue("Year"); - c1.setCellStyle(headerStyle); - - Cell c2 = r.createCell(1); - c2.setCellValue("Anomaly"); - c2.setCellStyle(headerStyle); - - Cell c3 = r.createCell(2); - c3.setCellValue("Smoothed"); - c3.setCellStyle(headerStyle); - } - - private void generateContent(Sheet s, TemperatureAnomaly[] temperatureAnomalys) { - CellStyle dateCellStyle = styles.get("dateCell"); - CellStyle numberCellStyle = styles.get("numberCell"); - - for (TemperatureAnomaly temperatureAnomaly : temperatureAnomalys) { - Row r = s.createRow(rowIndex++); - - Cell c1 = r.createCell(0); - c1.setCellValue(new DateTime(temperatureAnomaly.getYear(), 1, 1, 0, 0, 0, 0).toDate()); - c1.setCellStyle(dateCellStyle); - - Cell c2 = r.createCell(1); - c2.setCellValue(temperatureAnomaly.getAnomaly()); - c2.setCellStyle(numberCellStyle); - - Cell c3 = r.createCell(2); - c3.setCellValue(temperatureAnomaly.getSmoothed()); - c3.setCellStyle(numberCellStyle); - } - } - - private void generateTotals(Sheet s) { - - Row r = s.createRow(rowIndex++); - CellStyle totalStyle = styles.get("total"); - - //Cell强行分行 - Cell c1 = r.createCell(0); - c1.setCellStyle(totalStyle); - c1.setCellValue("合\n计"); - - //合计公式 - Cell c2 = r.createCell(1); - c2.setCellStyle(totalStyle); - c2.setCellFormula("SUM(B3:B32)"); - - Cell c3 = r.createCell(2); - c3.setCellStyle(totalStyle); - c3.setCellFormula("SUM(C3:C32)"); - } - - private Map createStyles(Workbook wb) { - styles = Maps.newHashMap(); - DataFormat df = wb.createDataFormat(); - - // --字体设定 --// - - //普通字体 - Font normalFont = wb.createFont(); - normalFont.setFontHeightInPoints((short) 10); - - //加粗字体 - Font boldFont = wb.createFont(); - boldFont.setFontHeightInPoints((short) 10); - boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); - - //蓝色加粗字体 - Font blueBoldFont = wb.createFont(); - blueBoldFont.setFontHeightInPoints((short) 10); - blueBoldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); - blueBoldFont.setColor(IndexedColors.BLUE.getIndex()); - - // --Cell Style设定-- // - - //标题格式 - CellStyle headerStyle = wb.createCellStyle(); - headerStyle.setFont(boldFont); - styles.put("header", headerStyle); - - //日期格式 - CellStyle dateCellStyle = wb.createCellStyle(); - dateCellStyle.setFont(normalFont); - dateCellStyle.setDataFormat(df.getFormat("yyyy")); - setBorder(dateCellStyle); - styles.put("dateCell", dateCellStyle); - - //数字格式 - CellStyle numberCellStyle = wb.createCellStyle(); - numberCellStyle.setFont(normalFont); - numberCellStyle.setDataFormat(df.getFormat("#,##0.00")); - setBorder(numberCellStyle); - styles.put("numberCell", numberCellStyle); - - //合计列格式 - CellStyle totalStyle = wb.createCellStyle(); - totalStyle.setFont(blueBoldFont); - totalStyle.setWrapText(true); - totalStyle.setAlignment(CellStyle.ALIGN_RIGHT); - setBorder(totalStyle); - styles.put("total", totalStyle); - - return styles; - } - - private void setBorder(CellStyle style) { - //设置边框 - style.setBorderRight(CellStyle.BORDER_THIN); - style.setRightBorderColor(IndexedColors.BLACK.getIndex()); - - style.setBorderLeft(CellStyle.BORDER_THIN); - style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); - - style.setBorderTop(CellStyle.BORDER_THIN); - style.setTopBorderColor(IndexedColors.BLACK.getIndex()); - - style.setBorderBottom(CellStyle.BORDER_THIN); - style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); - } -} diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp index 2e8eb35395432fa35a49f5a3a24ca5986be006e7..3ad4cec74362c96a6176b56b1d437047047927b0 100644 --- a/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp +++ b/examples/showcase/src/main/webapp/WEB-INF/views/story/utilizes.jsp @@ -19,28 +19,26 @@
  • 在JaxbDemo.java中演示XML与Java对象的转换及Dom4j的使用.
  • 在JsonDemo.java中演示Jackson远超同类JSON库的转化能力.
  • - -
    -

    Excel演示

    -

    说明:演示基于POI的Excel操作。

    - +
    +

    Email演示

    +
    +

    日志演示

    +
    +

    其他常用工具

    全部演示在org.springside.examples.showcase.utilities目录