jsp下载文件 excel

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.doshine.platform.util.SpringBeanUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.doshine.platform.dras.dao.SWellInfoDictDao"%>
<%@page import="com.doshine.platform.dras.dao.bean.WellInfoDictBean"%>
<%@page import="com.doshine.platform.util.StringUtil"%>
<%@page import="jxl.write.WritableWorkbook"%>
<%@page import="jxl.Workbook"%>
<%@page import="jxl.write.WritableSheet"%>
<%@page import="jxl.write.Label"%>
<%@page import="jxl.write.WritableFont"%>
<%@page import="jxl.format.UnderlineStyle"%>
<%@page import="jxl.format.Border"%>
<%@page import="jxl.format.BorderLineStyle"%>
<%@page import="jxl.format.Alignment"%>
<%
SWellInfoDictDao wellInfoDictDao =	(SWellInfoDictDao)SpringBeanUtil.getBean("SWellInfoDictDaoImpl");
WellInfoDictBean wellInfoDictBean = new WellInfoDictBean();
List list = wellInfoDictDao.search(wellInfoDictBean);
 %>

<%

String[] columnNames = {"井名","井号","隶属地址单元","生产单元(平台)","井别","井型"};
String name = "井注册表";
WritableWorkbook book = null;

	try {
		response.reset();

		response.setContentType("APPLICATION/OCTET-STREAM");
		response.setHeader("Content-Disposition", "attachment;filename=\""
				+ new String((name+".xls").getBytes("GBK"), "ISO8859-1") + "\"");

		book = Workbook.createWorkbook(response.getOutputStream());
		WritableSheet sheet = book.createSheet(name, 0);
		int size = list.size();
		
		jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false,UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); 
			jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);
			//设置单元格
			wcfFC.setBackground(jxl.format.Colour.YELLOW);
			wcfFC.setAlignment(Alignment.CENTRE);
			wcfFC.setBorder(Border.ALL,BorderLineStyle.DOTTED);
		for (int i=0;i<columnNames.length;i++)
		{
			Label label = new Label(i,0,columnNames[i],wcfFC);
			sheet.addCell(label);
		}
		for (int idx=0;idx<size;idx++)
		{
			
			
			WellInfoDictBean item = (WellInfoDictBean)list.get(idx);
			
			idx++;
			Label label = new Label(0,idx,item.getC_wellName());
			sheet.addCell(label);
			label = new Label(1,idx,item.getC_wellNo());
			sheet.addCell(label);
			
			label = new Label(2,idx,item.getC_geologicUnit());
			sheet.addCell(label);
			if (!StringUtil.isNullOrEmpty(item.getC_productUnit()))
			{
			label = new Label(3,idx,item.getC_productUnit());
			sheet.addCell(label);
			}
			if (!StringUtil.isNullOrEmpty(item.getC_wellType()))
			{
			label = new Label(4,idx,item.getC_wellType());
			sheet.addCell(label);
			}
			if (!StringUtil.isNullOrEmpty(item.getC_wellModel()))
			{
			label = new Label(5,idx,item.getC_wellModel());
			sheet.addCell(label);
			}
			
			idx--;
		}
		book.write();
	} catch (Exception e) {
	} finally {
		if (book != null)
			book.close();
		response.flushBuffer();
		out.clear();
		out = pageContext.pushBody();
	}
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值