struts2 中生成excel
来源:互联网 发布:网络蜘蛛工具下载 编辑:程序博客网 时间:2024/06/10 21:58
在使用前要引入jxl.jar
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.read.biff.PasswordException;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
/**
* 导出统计查询
* @return
* @throws Exception
*/
public String dcinformlist() {
try {
response.setContentType("application/msexcel");
String workSheetName ="12380简要情况汇总表";
workSheetName = new String(workSheetName.getBytes(), "ISO-8859-1");
response.setHeader("Content-disposition", "attachment; filename="
+ workSheetName + ".xls");
WritableWorkbook book = Workbook.createWorkbook(response.getOutputStream());
WritableSheet sheet = book.createSheet(workSheetName, 0);
sheet.setRowView(0, 1000, false);
sheet.mergeCells(0,0,6,0);
//用于excel格式设定
WritableFont wf_merge = new WritableFont(WritableFont.ARIAL, 24,WritableFont.BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat wff_merge = new WritableCellFormat(wf_merge);
wff_merge.setVerticalAlignment(VerticalAlignment.CENTRE); //垂直对齐
wff_merge.setAlignment(Alignment.CENTRE); //水平对齐
sheet.addCell(new Label(0,0,"12380简要情况汇总表",wff_merge));
//用于标题
WritableFont wfont = new WritableFont(WritableFont.ARIAL, 15,WritableFont.BOLD, false,jxl.format.UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.BLACK);
WritableCellFormat titleFormat = new WritableCellFormat(wfont);
titleFormat.setBorder(Border.ALL, BorderLineStyle.THIN); //线条
titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE); //垂直对齐
titleFormat.setAlignment(Alignment.CENTRE); //水平对齐
titleFormat.setWrap(false); //是否换行
//设置Excel表头
String[] stitle = { "时间", "举报人姓名","举报类型", "被举报人姓名或被举报单位名称", "所在地区", "被举报人所在单位", "被举报人职务" };
for (int i = 0; i < stitle.length; i++) {
Label excelTitle = new Label(i, 1, stitle[i], titleFormat);
sheet.addCell(excelTitle);
}
sheet.setColumnView(0 , 15);
sheet.setColumnView(1 , 20);
sheet.setColumnView(2 , 15);
sheet.setColumnView(3 , 50);
sheet.setColumnView(4 , 20);
sheet.setColumnView(5 , 30);
sheet.setColumnView(6 , 20);
//读取发文数据
WritableFont content = new WritableFont(WritableFont.ARIAL, 8,WritableFont.NO_BOLD, false);
WritableCellFormat forcontent = new WritableCellFormat(content);
forcontent.setVerticalAlignment(VerticalAlignment.CENTRE); //垂直对齐
forcontent.setAlignment(Alignment.CENTRE); //水平对齐
forcontent.setWrap(false); //是否换行
List lis=(List)session.getAttribute("viewlist");
for(int i=0;i<lis.size();i++){
Inform entry= (Inform)lis.get(i);
String acceptanceTime = "";
if(null != entry.getAcceptanceTime())
acceptanceTime = entry.getAcceptanceTime();
String fmenName = "";
if(null != entry.getFmenName())
fmenName= entry.getFmenName();
String InformType = "";
if(1 == entry.getInformType())
InformType = "个人举报";
else
InformType = "单位举报";
String tmenName = "";
if(1 == entry.getInformType())
tmenName = entry.getTmenName();
else
tmenName = entry.getDunitName();
String tarea = "";
if(null != entry.getTarea())
tarea = entry.getTarea();
String tunit = "";
if(null != entry.getTunit())
tunit = entry.getTunit();
String tposition = "";
if(null != entry.getTposition())
tposition = entry.getTposition();
Label enumbber = new Label(0, i+2,acceptanceTime, forcontent);
Label etitle = new Label(1, i+2,fmenName, forcontent);
Label unitname = new Label(2, i+2,InformType , forcontent);
Label eprint = new Label(3, i+2,tmenName , forcontent);
Label etime = new Label(4, i+2,tarea, forcontent);
Label euser = new Label(5, i+2,tunit ,forcontent);
Label er = new Label(6, i+2,tposition ,forcontent);
sheet.addCell(enumbber);
sheet.addCell(etitle);
sheet.addCell(unitname);
sheet.addCell(eprint);
sheet.addCell(etime);
sheet.addCell(euser);
sheet.addCell(er);
}
book.write();
book.close();
return null;
} catch (Exception e) {
e.printStackTrace();
return "error";
}
}
- struts2 中生成excel
- struts2中生成二维码
- EXCEL 中生成GUID
- Flex中生成Excel
- android中生成excel
- android中生成excel
- android中生成excel
- Struts2 + poi 动态生成Excel 下载
- struts2+spring+hibernate如何生成Excel文件
- struts2生成excel文件和下载
- struts2 生成并下载 excel 文件 (jxl)
- struts2中生成验证码
- java中下载生成Excel
- struts2中使用poi导出excel数据
- struts2中使用poi导入excel数据
- 在Struts2中利用JasperReport导出excel
- Struts2+POI 实现生成Excel文件和下载
- Struts2中验证码的生成技术
- tar版mysql集群安装
- 快速排序改进
- 移动加权平均法
- tar版mysql集群安装
- Oracle Savepoint
- struts2 中生成excel
- S3C6410的GPIO流驱动(WINCE600)
- PPI install-locate and notify-install method
- OpenCV的移植
- (转)multipart form-data boundary 说明
- 如何避免Exception
- App Store 申请经验 完整的IDP申请直到软件上架销售流程
- 关于c++的多态的实现
- “.NET 4.0网络开发入门之旅系列文章”开篇语—— 无网不胜(上)