测试分页查询出数据并分文件导出[java工程]

 1 package cn.shiyanjun.test;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 
 6 public class ExcelTest3 {
 7     List<Integer> rowData = getRowData(17);
 8     public static void main(String[] args) {
 9         ExcelTest3 excelTest3 = new ExcelTest3();
10         excelTest3.exportExcelTest();    
11     }
12 
13 //    ==================================================================================================
14     public void exportExcelTest() {
15         int dataCount = rowData.size();//数据总数59
16         int exNum = 6;//每个文件导出数
17         int qryNum = 8;//已知查询数
18         int qryCount = getCount(dataCount,qryNum);
19         int end = 1;
20         int fileNum = 0;
21         List<Integer> list = new ArrayList<Integer>();
22         
23         for (int i = 0; i < qryCount; i++) {
24             List<Integer> beanList = new ArrayList<Integer>();
25             if(i != (qryCount - 1)){//如果不是最后一次查询
26                 beanList = queryForPage(i*qryNum, (i+1)*qryNum);//一次查8条
27             }else{
28                 beanList = rowData.subList(i*qryNum, dataCount);
29             }
30             for (int j = 0; j < beanList.size(); j++) {//遍历这8条数据
31                 list.add(beanList.get(j));
32                 if(list.size() == exNum || (end ==qryCount && j == beanList.size() -1 )){
33                     System.out.println((fileNum+1) + ".xls");//创建文件
34                     System.out.println("导出"+list.size()+"条数据:"+list);
35                     list.clear();
36                     fileNum++;
37                 }
38             }
39             end++;
40         }
41         
42 
43     }
44     
45     public List<Integer> queryForPage(int startIndex, int pageSize){
46         List<Integer> pageData = rowData.subList(startIndex, pageSize);
47         return pageData;
48     }
49 
50     
51     //根据count和rows来计算个数
52     public int getCount(int count, int rows) {
53         int num = 1;
54         if(count >= rows){
55             if(count % rows == 0){
56                 num = count/rows;
57             }else{
58                 num = count/rows + 1;
59             }
60         }
61         return num;
62     }
63     
64     
65     //创建一个包含若干2位随机整数的list集合
66     public List<Integer> getRowData(int count){
67         List<Integer> list = new ArrayList<Integer>();
68         for(int i = 0; i < count; i++){
69 //            int num = (int) Math.round(Math.random()*90+10);
70             list.add(i);
71         }
72         return list;
73     }
74     
75     public void printExcelApi(List<Integer> exList, List<Integer> list){
76         exList.addAll(list);
77     }
78 
79 }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值