01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.actiontest.actions;
16:
17: import java.util.Date;
18: import java.util.Map;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: import org.apache.poi.hssf.usermodel.HSSFCell;
24: import org.apache.poi.hssf.usermodel.HSSFCellStyle;
25: import org.apache.poi.hssf.usermodel.HSSFDataFormat;
26: import org.apache.poi.hssf.usermodel.HSSFSheet;
27: import org.apache.poi.hssf.usermodel.HSSFWorkbook;
28: import org.springframework.web.servlet.ModelAndView;
29: import org.springframework.web.servlet.View;
30: import org.springframework.web.servlet.view.document.AbstractExcelView;
31: import org.strecks.action.NavigableAction;
32: import org.strecks.action.navigable.NavigableController;
33: import org.strecks.controller.annotation.Controller;
34: import org.strecks.navigate.spring.annotation.SpringView;
35:
36: /**
37: * @author Phil Zoio
38: */
39: @Controller(name=NavigableController.class)
40: public class SpringExcelViewAction implements NavigableAction {
41:
42: public void execute() {
43: }
44:
45: @SpringView()
46: public ModelAndView getResult() {
47: View view = new AbstractExcelView() {
48:
49: protected void buildExcelDocument(Map model,
50: HSSFWorkbook workbook, HttpServletRequest request,
51: HttpServletResponse response) throws Exception {
52: HSSFSheet sheet = workbook
53: .createSheet("Spring Excel View");
54: sheet.setDefaultColumnWidth((short) 12);
55:
56: // Write a text at A1.
57: HSSFCell cell = getCell(sheet, 0, 0);
58: setText(cell, "Spring Excel View Via Strecks");
59:
60: // Write the current date at A2.
61: HSSFCellStyle dateStyle = workbook.createCellStyle();
62: dateStyle.setDataFormat(HSSFDataFormat
63: .getBuiltinFormat("m/d/yy"));
64: cell = getCell(sheet, 1, 0);
65: cell.setCellValue(new Date());
66: cell.setCellStyle(dateStyle);
67: }
68: };
69: return new ModelAndView(view);
70: }
71:
72: }
|