<%@ 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();
}
%>
jsp下载文件 excel
最新推荐文章于 2023-02-15 20:05:52 发布