Package org.strecks.actiontest.actions

Source Code of org.strecks.actiontest.actions.SpringExcelViewAction

/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.strecks.actiontest.actions;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.document.AbstractExcelView;
import org.strecks.action.NavigableAction;
import org.strecks.action.navigable.NavigableController;
import org.strecks.controller.annotation.Controller;
import org.strecks.navigate.spring.annotation.SpringView;

/**
* @author Phil Zoio
*/
@Controller(name = NavigableController.class)
public class SpringExcelViewAction implements NavigableAction
{

  public void execute()
  {
  }

  @SpringView()
  public ModelAndView getResult()
  {
    View view = new AbstractExcelView()
    {

      protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request,
          HttpServletResponse response) throws Exception
      {
        HSSFSheet sheet = workbook.createSheet("Spring Excel View");
        sheet.setDefaultColumnWidth((short) 12);

        // Write a text at A1.
        HSSFCell cell = getCell(sheet, 0, 0);
        setText(cell, "Spring Excel View Via Strecks");

        // 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);
      }
    };
    return new ModelAndView(view);
  }

}
TOP

Related Classes of org.strecks.actiontest.actions.SpringExcelViewAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.