内容分多个excel文件进行存储数据
来源:互联网 发布:如何成为淘宝砍价师 编辑:程序博客网 时间:2024/05/22 01:07
/** * 分多个excel文件进行存储数据 * @author hanchuang * */ public class AccessExcel { String[] titleCell; String[][] allCell; jxl.Workbook workBook; Sheet sheet; int cell; int column; /* * 将相关的数据存储到数组中 */ //1、列数;2、文件内容;3、文件路径;4、需要分隔的行数 public void readExcel(int columns,String content,String fileurl,int number) { column=columns; String []cellname=content.substring(content.indexOf("。")).split(","); Arrays.fill(cellname,0,1,cellname[0].substring(1, cellname[0].length()));//去掉分隔符“。” cell=cellname.length/column;//---多少行数据 allCell = new String[cell][column]; //共多少条数据;多少列----- for(int i = 0 ;i<allCell.length;i++){ //初始化表格数据 for(int j = 0;j<allCell[0].length;j++){ for(int hc=(j+i*column);hc<(j+1+i*column);hc++){ allCell[i][j]=cellname[hc]; } } } titleCell=content.substring(0, content.indexOf("。")).split(",");//表头 //将数组内容放入excel中 splitExcel(number, fileurl); } /* *@param number代表需要分隔的行数 *@param fileurl代表分隔文件后存储的路径 */ public void splitExcel(int number, String fileurl) { int index = (int) Math.ceil(cell / number);//计算需要分隔多少个文件 File[] files = new File[index + 1]; //初始化文件数组 for (int i = 0; i <= index; i++) { files[i] = new File(fileurl +"("+i+")" + ".xls"); } int n = number; int y = 0;//用于记录行的位置 for (int i = 0; i <= index; i++) { try { jxl.write.WritableWorkbook ww = Workbook .createWorkbook(files[i]); WritableSheet ws = ww.createSheet("sheet1", 0); //设置表格表头 for (int t = 0; t <column; t++) { ws.addCell(new Label(t, 0, titleCell[t])); } //将数组中的内容放入表格单元格中 out: for (int m = 1; y < cell; y++, m++) { for (int x = 0; x < column; x++) { if (y >number) { number += n; break out; } ws.addCell(new Label(x, m, allCell[y][x])); } } ww.write(); ww.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RowsExceededException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { String content="count(0),处理日期,处理时间。1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9," + "1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9," + "1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,1,2,3,4,5,6,7,8,9,9,0"; AccessExcel ae = new AccessExcel(); ae.readExcel(3,content,"D:\\timingNums\\hanchuang",19); } }
阅读全文
0 0
- 内容分多个excel文件进行存储数据
- 使用文件进行数据存储及读取文件内容
- 文件进行数据存储
- 使用文件进行数据存储
- 使用文件进行数据存储
- 使用文件进行数据存储
- 使用文件进行数据存储
- Android 数据存储 之 使用文件进行数据存储
- 使用文件对数据进行存储、访问
- android之使用文件进行数据存储
- android基础---使用文件进行数据存储
- 使用文件进行数据存储的模式
- Android之使用文件进行数据存储
- 五、使用文件进行数据存储
- 五、使用文件进行数据存储
- 四、用文件对数据进行存储
- Android如何使用文件进行数据存储
- 读取Excel文件,将内容存储在DataSet中
- 九宫格拖拽
- VBOX,VMWare下的网络共享
- 技术共享之手写广告条(ViewPager)
- Javascript学习笔记(CSS操作)
- 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
- 内容分多个excel文件进行存储数据
- 使用多线程优化批量导入的回显功能
- 新路程------imx6 i2c clk频率修改
- 调用系统相册或拍照时使用中文字体显示
- C#游戏开发基础04
- angularJs中forEach两种用法
- Spring Security及与Shiro的比较
- MongoDB数据导入导出,备份,安全认证(七)
- caffe ssd gpu