我是靠谱客的博主 害羞小丸子,最近开发中收集的这篇文章主要介绍用jxl导出资料创建多个sheet(克服大数据量的导出),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

用过jxl的一看就明白了

<%@page import="jxl.write.WritableFont,jxl.write.WritableCellFormat,java.sql.ResultSetMetaData,java.io.*,jxl.write.Label,java.net.*,jxl.write.WritableCell,jxl.write.WritableWorkbook,
	java.util.*,com.running.crm.model.*,jxl.Workbook,jxl.write.WritableSheet"
	contentType="application/x-msdownload" pageEncoding="utf-8"%>
	<%
	OutputStream os = response.getOutputStream();
	WritableWorkbook wwb = Workbook.createWorkbook(os);
	Label label;
	response.setHeader("Content-disposition", "attachment; filename="+ URLEncoder.encode("客户资料", "utf-8") + ".xls");
	List customers=(List<Customer>)request.getAttribute("billResultSet");
	//String deptName=(String)request.getAttribute("deptName");
	int length=customers.size();//查询结果记录数
	int sheetSize=20000;
	int sheetNum=1;
	if(length%sheetSize>0){
	   sheetNum=length/sheetSize+1;
	}else{
	   sheetNum=length/sheetSize;
	}
	for(int kk=0;kk<sheetNum;kk++){
        WritableSheet ws=wwb.createSheet(("查询结果"+kk),kk);	
          //设定第一行的行高
         ws.setRowView(0,320);
         //将第一列的宽度设为20 
         
         ws.setColumnView(0,15);
         ws.setColumnView(1,15);
         ws.setColumnView(2,20);
         ws.setColumnView(3,20);
         ws.setColumnView(4,20);
         ws.setColumnView(5,20);
         ws.setColumnView(6,20);
         ws.setColumnView(7,20);
        
             
		String ss[] = {"姓名","性别","手机号码","证件类型","证件号码","公司","家庭住址","爱好" };
	  for (int i = 0; i < 8; i++) {
		 WritableFont arial12pt = new WritableFont(WritableFont.ARIAL,11, WritableFont.BOLD);
		 WritableCellFormat arial12format = new WritableCellFormat(arial12pt);
		 arial12format.setWrap(false);
		 label = new Label(i, 0, ss[i], arial12format);
		 ws.addCell(label);
	    }
	  for(int i = kk*sheetSize; i< (kk+1)*sheetSize ; i++ ){
         if(i<length ){
                   Customer customer = (Customer) customers.get(i);
           for (int j = 0; j < 8; j++) {
            switch(j){
                case 0:label=new  Label(j, i+1-(kk*sheetSize), customer.getCustomerName());break;
                case 1:label=new  Label(j,i+1-(kk*sheetSize), customer.getCustomerSex());break;
                case 2:label=new  Label(j, i+1-(kk*sheetSize), customer.getPhoneNo());break;
              //  case 3:lable=new  Label(j, i, customer.getCategoryName());break;
                case 3:label=new  Label(j, i+1-(kk*sheetSize), customer.getCardType());break;
                case 4:label=new  Label(j, i+1-(kk*sheetSize), customer.getCardId());break;
                case 5:label=new  Label(j, i+1-(kk*sheetSize), customer.getCustomerCorp());break;
                case 6:label=new  Label(j, i+1-(kk*sheetSize), customer.getHomeAddr());break;
                case 7:label=new  Label(j, i+1-(kk*sheetSize), customer.getCustomerJoy());break;
                default:label=new Label(j,i+1-(kk*sheetSize),"");
                
            }
           
			ws.addCell(label);
		}
           }else{
                break;
            }
	    }
	 }
	  wwb.write();
	  wwb.close();
	  os.close();
      out.clear();
      out = pageContext.pushBody();
	  return;
%>

 

最后

以上就是害羞小丸子为你收集整理的用jxl导出资料创建多个sheet(克服大数据量的导出)的全部内容,希望文章能够帮你解决用jxl导出资料创建多个sheet(克服大数据量的导出)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部