Package demo

Source Code of demo.ExcelServlet

package demo;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.format.UnderlineStyle;
import jxl.write.WritableFont;


import com.trulytech.mantis.system.ActionServlet;
import com.trulytech.mantis.system.Permission;
import com.trulytech.mantis.system.SQLParser;
import com.trulytech.mantis.util.ExcelWriter;

/**
* Excel处理类
* @author wangxian
*
*/
public class ExcelServlet extends ActionServlet {

  // 重载身份校验函数
  protected int HasPermission(HttpServletRequest request,
      HttpServletResponse response, SQLParser Parser) throws Exception {
    return Permission.ALLOW;
  }
 
  /**
   * 导出Excel
   * @param request
   * @param response
   * @param Parser
   * @return
   * @throws Exception
   */
  public String exportExcel(HttpServletRequest request,
      HttpServletResponse response, SQLParser Parser) throws Exception

  {
    response.setContentType("application/msexcel");
      response.setHeader("Content-Disposition", " filename=report.xls");
     
      ServletOutputStream ouputStream = response.getOutputStream();
      ExcelWriter writer = new ExcelWriter(ouputStream);
      writer.createSheet("信息表", 0);
     
      writer.mergeCells(0, 0, 0, 14, 0);
     
      WritableFont font = new WritableFont(WritableFont.ARIAL, 16,
                WritableFont.BOLD, false,
                UnderlineStyle.NO_UNDERLINE,
                jxl.format.Colour.BLACK);
      writer.writeStyleString(0, 0, 0, "会员信息表", font,
                jxl.format.Alignment.CENTRE);
      //表头
      writer.writeString(0, 0, 1, "登陆名");
      writer.writeString(0, 1, 1, "密码");
      writer.writeString(0, 2, 1, "真实姓名");
      writer.writeString(0, 3, 1, "性别");
      writer.writeString(0, 4, 1, "电话");
      writer.writeString(0, 5, 1, "手机");
      writer.writeString(0, 6, 1, "电子邮件");
      writer.writeString(0, 7, 1, "国家和地区");
      writer.writeString(0, 8, 1, "城市");
      writer.writeString(0, 9, 1, "邮编");
      writer.writeString(0, 10, 1, "地址");
      writer.writeString(0, 11, 1, "公司");
      writer.writeString(0, 12, 1, "刊物名称");
      writer.writeString(0, 13, 1, "用户类型");
   
      writer.flush();
      writer.close();
   
      ouputStream.flush();
      ouputStream.close();

    return "";
  }
}
TOP

Related Classes of demo.ExcelServlet

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.