@SuppressWarnings("unchecked") public static void downLoad( List downList, String fileName, HttpServletResponse httpResponse, String downLoadId) { // 获取列对象集合 httpResponse.reset(); List columnList = new ArrayList(); try { // 初始化参数 DownloadBean downloadBean = DownloadContentHelper.getDownloadBean(downLoadId); columnList = downloadBean.getAttributes(); } catch (Exception e) { } OutputStream output = null; try { output = httpResponse.getOutputStream(); httpResponse.setContentType("application/vnd.ms-excel; charset=GBK"); httpResponse.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls"); WritableWorkbook w = Workbook.createWorkbook(output); output.flush(); // 分sheet页操作start List<Object> newTotals = new ArrayList<Object>(); Iterator itTotals = downList.iterator(); while (itTotals.hasNext()) { newTotals.add(itTotals.next()); } int sheetNum = 0; while (newTotals.size() > MisConstants.MAXNUM_FOR_PER_SHEET) { WritableSheet ws = w.createSheet("Page" + (sheetNum + 1), sheetNum); addLabelExcel(ws, newTotals.subList(0, MisConstants.MAXNUM_FOR_PER_SHEET), columnList); newTotals.subList(0, MisConstants.MAXNUM_FOR_PER_SHEET).clear(); sheetNum = sheetNum + 1; } WritableSheet ws = w.createSheet("Page" + (sheetNum + 1), sheetNum); addLabelExcel(ws, newTotals, columnList); // 分sheet页操作end w.write(); // 关闭Excel工作薄对象 w.close(); if (output != null) output.close(); } catch (Exception e) { if (output != null) try { output.close(); } catch (IOException e1) { } e.printStackTrace(); } }
public SingleNameReport(WritableWorkbook workbook, Statement new_statement, String[] arguments) { String main_tsn = ""; String main_rank = ""; String main_kingdom = ""; row = 0; try { statement = new_statement; func = new AdditionalFunctions(statement); copy = workbook; kingdom = arguments[0]; hrank = arguments[1]; lrank = arguments[2]; scientificName = arguments[3]; date_from = arguments[4]; date_to = arguments[5]; user = arguments[6]; String temp = ""; temp = "SELECT tsn,rank_id,kingdom_id from Tree where scientificName='" + scientificName + "'"; System.out.println(temp); result = statement.executeQuery(temp); metadata = result.getMetaData(); int numberOfRows = 0; int hrankVal = Integer.parseInt(hrank); int main_rankVal = 0; if (result.last()) numberOfRows = result.getRow(); result.first(); if (numberOfRows > 0 && metadata.getColumnCount() > 0) { main_tsn = result.getString(1); main_rank = result.getString(2); main_rankVal = Integer.parseInt(main_rank); main_kingdom = result.getString(3); } if (HasChildren(main_tsn) == true) FindChildInformation(main_tsn, arguments, func); FileInFrontPage frontPage = new FileInFrontPage(copy, statement, arguments); copy.write(); copy.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } // end of constructor