日期:2014-05-17 浏览次数:20730 次
FileOutputStream out=new FileOutputStream(path+fileName_exp,true); //File wbook = new File(path+fileName_exp); WritableWorkbook book = Workbook.createWorkbook(out); WritableSheet sheet = book.createSheet("移动电话号段表数据", 0); Label label = new Label(0, 0, "号段ID"); sheet.addCell(label); label = new Label(1, 0, "号段低位"); sheet.addCell(label); label = new Label(2, 0, "号段高位"); sheet.addCell(label); label = new Label(3, 0, "号段归属地区号"); sheet.addCell(label); label = new Label(4, 0, "运营商"); sheet.addCell(label); label = new Label(5, 0, "生效时间"); sheet.addCell(label); label = new Label(6, 0, "失效时间"); sheet.addCell(label); [color=#FF0000]for (int i=1000,j=1;i<count;j++) { fileName = importSheet(hashSet.iterator(),fileName_exp,path,book,sheet,out,i*(j-1)+1); Workbook newWorkBook = Workbook.getWorkbook(new File(path+fileName_exp)); book = Workbook.createWorkbook(new File(path+fileName_exp), newWorkBook); sheet = book.getSheet("移动电话号段表数据"); }[/color] //写入到excel中的函数 public String importSheet(Iterator it,String fileName,String path,WritableWorkbook book,WritableSheet sheet,FileOutputStream out,int i) throws Exception{ //filename是生成文件的路径及用户名;it是内容, Iterator it; try { int row = i; for (; it.hasNext(); ) { OcsProdCellMsisdn vo = (OcsProdCellMsisdn) it.next(); Label xm = new Label(0, row, vo.getMsisdnId()); sheet.addCell(xm); Label username = new Label(1, row, vo.getMsisdnFirst()); sheet.addCell(username); Label pwd = new Label(2, row, vo.getMsisdnLast()); sheet.addCell(pwd); pwd = new Label(3, row, vo.getAreaCode()); sheet.addCell(pwd); pwd = new Label(4, row, vo.getOperatorCode()); sheet.addCell(pwd); pwd = new Label(5, row, vo.getEffDate()); sheet.addCell(pwd); pwd = new Label(6, row, vo.getExpDate()); sheet.addCell(pwd); row++; } book.write(); book.close(); out.flush(); //out.close(); } catch (Exception e) { e.printStackTrace(); } return fileName; }