首页 > 代码库 > jxl实现的导出excel的功能
jxl实现的导出excel的功能
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="jxl.Workbook"%>
<%@ page import="jxl.format.Alignment"%>
<%@ page import="jxl.format.Border"%>
<%@ page import="jxl.format.BorderLineStyle"%>
<%@ page import="jxl.format.Colour"%>
<%@ page import="jxl.format.UnderlineStyle"%>
<%@ page import="jxl.write.Label"%>
<%@ page import="jxl.write.WritableCellFormat"%>
<%@ page import="jxl.write.WritableFont"%>
<%@ page import="jxl.write.WritableSheet"%>
<%@ page import="jxl.write.WritableWorkbook"%>
<%@ page import="jxl.write.WriteException"%>
<%
response.reset();
response.addHeader("Content-Disposition", "attachment;filename="+new String("1.xls".getBytes("GB2312"),"ISO8859-1"));
WritableWorkbook wwb = Workbook.createWorkbook(response.getOutputStream());
WritableSheet ws = wwb.createSheet("报表", 0);
int[] colsWidth = new int[2];
WritableFont wfc = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat wcfFC = new WritableCellFormat(wfc);
wcfFC.setAlignment(Alignment.CENTRE);
wcfFC.setBorder(Border.ALL, BorderLineStyle.THIN);
Label heaLabel = new Label(0,0,"id",wcfFC);
ws.addCell(heaLabel);
heaLabel = new Label(1,0,"name",wcfFC);
ws.addCell(heaLabel);
heaLabel = new Label(0,1,"1",wcfFC);
ws.addCell(heaLabel);
heaLabel = new Label(1,1,"1",wcfFC);
ws.addCell(heaLabel);
wwb.write();
wwb.close();
out.clear();
out = pageContext.pushBody();
%>
简单的实现留作以后如果忘记了还可以再看看