package cn.shiyanjun.test; import java.util.ArrayList;
import java.util.List; public class ExcelTest3 {
List<Integer> rowData = getRowData(17);
public static void main(String[] args) {
ExcelTest3 excelTest3 = new ExcelTest3();
excelTest3.exportExcelTest();
} // ==================================================================================================
public void exportExcelTest() {
int dataCount = rowData.size();//数据总数59
int exNum = 6;//每个文件导出数
int qryNum = 8;//已知查询数
int qryCount = getCount(dataCount,qryNum);
int end = 1;
int fileNum = 0;
List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < qryCount; i++) {
List<Integer> beanList = new ArrayList<Integer>();
if(i != (qryCount - 1)){//如果不是最后一次查询
beanList = queryForPage(i*qryNum, (i+1)*qryNum);//一次查8条
}else{
beanList = rowData.subList(i*qryNum, dataCount);
}
for (int j = 0; j < beanList.size(); j++) {//遍历这8条数据
list.add(beanList.get(j));
if(list.size() == exNum || (end ==qryCount && j == beanList.size() -1 )){
System.out.println((fileNum+1) + ".xls");//创建文件
System.out.println("导出"+list.size()+"条数据:"+list);
list.clear();
fileNum++;
}
}
end++;
} } public List<Integer> queryForPage(int startIndex, int pageSize){
List<Integer> pageData = rowData.subList(startIndex, pageSize);
return pageData;
} //根据count和rows来计算个数
public int getCount(int count, int rows) {
int num = 1;
if(count >= rows){
if(count % rows == 0){
num = count/rows;
}else{
num = count/rows + 1;
}
}
return num;
} //创建一个包含若干2位随机整数的list集合
public List<Integer> getRowData(int count){
List<Integer> list = new ArrayList<Integer>();
for(int i = 0; i < count; i++){
// int num = (int) Math.round(Math.random()*90+10);
list.add(i);
}
return list;
} public void printExcelApi(List<Integer> exList, List<Integer> list){
exList.addAll(list);
} }