List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook write
private void write(POIFSFileSystem fs) throws IOException
From source file:Clavis.Windows.WShedule.java
public void createXLSDocument(String nome, String[][] valores) { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(nome); HSSFRow row;// w w w. j a va 2s . c o m HSSFCell cell; for (int i = 0; i < valores.length; i++) { row = sheet.createRow(i); for (int j = 0; j < valores[i].length; j++) { cell = row.createCell(j); cell.setCellValue(valores[i][j]); if (valores[i][j] != null) { sheet.setColumnWidth(j, 255 * valores[i][j].length() + 4); CellUtil.setAlignment(cell, wb, CellStyle.ALIGN_CENTER); } } } wb.setPrintArea(0, 0, valores[0].length, 0, valores.length); sheet.getPrintSetup().setPaperSize(XSSFPrintSetup.A4_PAPERSIZE); FileOutputStream out; String sfile = new File("").getAbsolutePath() + System.getProperty("file.separator") + nome; File file = new File(sfile); if (!file.exists()) { try { file.createNewFile(); } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } } if (file.canWrite()) { try { out = new FileOutputStream(file); } catch (FileNotFoundException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); out = null; } if (out != null) { try { wb.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } else { Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO, painelcor, lingua.translate("Nota"), 400, 200, lingua.translate("O documento \"doc.xls\" foi criado na pasta raiz do programa") + ".", new String[] { lingua.translate("Voltar") }); mensagem.showMessage(); } } catch (IOException ex) { Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:cliente.ReclamoPiezas.GUINuevoReclamoFabrica.java
License:Open Source License
protected void llenarFormulario() { String archivo = "Formulario_SRC.xls"; Date hoy = new Date(); String nombre_archivo = pedido_pieza.getPedido().getReclamo().getReclamante().getNombre_apellido() + "_pedido_" + pedido_pieza.getNumero_pedido(); Boolean inmovilizado = pedido_pieza.getPedido().getReclamo().getInmovilizado(); String vin = pedido_pieza.getPedido().getReclamo().getVehiculo().getVin(); String dominio = pedido_pieza.getPedido().getReclamo().getVehiculo().getDominio(); String nombre_cliente = pedido_pieza.getPedido().getReclamo().getReclamante().getNombre_apellido(); String telefono = mediador.obtenerTelefono(pedido_pieza); try {//from w ww. ja v a2s . co m InputStream ExcelFileToRead = new FileInputStream("Formulario_SRC.xls"); HSSFWorkbook formulario_src = new HSSFWorkbook(ExcelFileToRead); HSSFSheet sheet = formulario_src.getSheetAt(0); HSSFRow row; HSSFCell cell; //tipo reclamo row = sheet.getRow(10); cell = row.getCell(4); cell.setCellValue("Repuestos"); //inmovilizado if (inmovilizado) { row = sheet.getRow(11); cell = row.getCell(4); cell.setCellValue("Si"); } else { row = sheet.getRow(11); cell = row.getCell(4); cell.setCellValue("No"); } //garantia row = sheet.getRow(12); cell = row.getCell(4); cell.setCellValue("Si"); //Vin row = sheet.getRow(15); cell = row.getCell(4); cell.setCellValue(vin); //dominio row = sheet.getRow(16); cell = row.getCell(4); cell.setCellValue(dominio); //modelo LinkedList<String> modelos = new LinkedList<String>(); modelos.add("FLUENCE"); modelos.add("CLIO"); modelos.add("KANGOO"); modelos.add("SYMBOL"); modelos.add("LOGAN"); modelos.add("SANDERO"); modelos.add("MASTER"); modelos.add("KOLEOS"); modelos.add("MEGANE III"); modelos.add("DUSTER"); modelos.add("LATITUDE"); if (modelos.contains(pedido_pieza.getPedido().getReclamo().getVehiculo().getModelo().getNombre_modelo() .toUpperCase())) { row = sheet.getRow(17); cell = row.getCell(4); cell.setCellValue(pedido_pieza.getPedido().getReclamo().getVehiculo().getModelo().getNombre_modelo() .toUpperCase()); } else { row = sheet.getRow(17); cell = row.getCell(4); cell.setCellValue("OTROS"); } //nombre cliente row = sheet.getRow(11); cell = row.getCell(8); cell.setCellValue(nombre_cliente); //telefono row = sheet.getRow(12); cell = row.getCell(8); cell.setCellValue(telefono); //motivo row = sheet.getRow(21); cell = row.getCell(2); cell.setCellValue(ePMotivo.getText()); //pieza row = sheet.getRow(33); cell = row.getCell(3); cell.setCellValue(pedido_pieza.getPieza().getNumero_pieza()); row = sheet.getRow(33); cell = row.getCell(4); cell.setCellValue(pedido_pieza.getPieza().getDescripcion()); row = sheet.getRow(33); cell = row.getCell(7); cell.setCellValue("1"); row = sheet.getRow(33); cell = row.getCell(8); cell.setCellValue(pedido_pieza.getNumero_pedido()); //write this workbook to an Outputstream. int i = 0; String aux = nombre_archivo; File formulario_guardado = new File(RootAndIp.getPath_reportes() + aux + ".xls"); while (formulario_guardado.exists()) { aux = nombre_archivo + "_" + i; formulario_guardado = new File(RootAndIp.getPath_reportes() + aux + ".xls"); i++; } FileOutputStream fileOut = new FileOutputStream(formulario_guardado); formulario_src.write(fileOut); fileOut.flush(); fileOut.close(); Desktop.getDesktop().open(formulario_guardado); formulario = formulario_guardado.getPath(); btnVerFormulario.setEnabled(true); btnEnviarFormulario.setEnabled(true); } catch (Exception e) { e.printStackTrace(); } }
From source file:cn.edu.henu.rjxy.lms.controller.Acdemic.java
@RequestMapping("daochuxuesheng") public void daochuxuesheng(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); session.setAttribute("state", null); // ???? /*from w ww . j ava2 s.c om*/ response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "student_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("qq"); cell.setCellStyle(style); List allstudent = StudentDao.getAllStudent(); for (int i = 0; i < allstudent.size(); i++) { StudentWithoutPwd tmp = (StudentWithoutPwd) allstudent.get(i); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(tmp.getStudentSn()); row.createCell((short) 1).setCellValue(tmp.getStudentName()); row.createCell((short) 2).setCellValue(tmp.getStudentIdcard()); row.createCell((short) 3).setCellValue(tmp.getStudentGrade()); row.createCell((short) 4).setCellValue((tmp.isStudentSex()) ? ("") : ("")); row.createCell((short) 5).setCellValue(tmp.getStudentCollege()); row.createCell((short) 6).setCellValue(tmp.getStudentTel()); row.createCell((short) 7).setCellValue(tmp.getStudentQq()); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); }
From source file:cn.edu.henu.rjxy.lms.controller.Acdemic.java
@RequestMapping("daochualltoxls") public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); System.out.println("1..."); session.setAttribute("state", null); // ???? /* w w w . j a v a2s .c o m*/ response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "teacher_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("qq"); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue(""); cell.setCellStyle(style); List allteacher = TeacherDao.getAllTeacher(); for (int i = 0; i < allteacher.size(); i++) { TempTeacherWithoutPwd tmp = (TempTeacherWithoutPwd) allteacher.get(i); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(tmp.getTeacherSn()); row.createCell((short) 1).setCellValue(tmp.getTeacherName()); row.createCell((short) 2).setCellValue(tmp.getTeacherIdcard()); row.createCell((short) 3).setCellValue(tmp.getTeacherPosition()); row.createCell((short) 4).setCellValue(tmp.getTeacherCollege()); row.createCell((short) 5).setCellValue(tmp.getTeacherQq()); row.createCell((short) 6).setCellValue(tmp.getTeacherTel()); row.createCell((short) 7).setCellValue((tmp.getTeacherSex()) ? ("") : ("")); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); }
From source file:cn.edu.henu.rjxy.lms.controller.DeanController.java
@RequestMapping("dean/daochuxuesheng") public void daochuxuesheng(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); session.setAttribute("state", null); // ???? //from w w w .j a v a2 s . c o m response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "student_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("qq"); cell.setCellStyle(style); List allstudent = StudentDao.getAllStudent(); for (int i = 0; i < allstudent.size(); i++) { StudentWithoutPwd tmp = (StudentWithoutPwd) allstudent.get(i); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(tmp.getStudentSn()); row.createCell((short) 1).setCellValue(tmp.getStudentName()); row.createCell((short) 2).setCellValue(tmp.getStudentIdcard()); row.createCell((short) 3).setCellValue(tmp.getStudentGrade()); row.createCell((short) 4).setCellValue((tmp.isStudentSex()) ? ("") : ("")); row.createCell((short) 5).setCellValue(tmp.getStudentCollege()); row.createCell((short) 6).setCellValue(tmp.getStudentTel()); row.createCell((short) 7).setCellValue(tmp.getStudentQq()); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); }
From source file:cn.edu.henu.rjxy.lms.controller.DeanController.java
@RequestMapping("dean/daochualltoxls") public void exportExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); System.out.println("1..."); session.setAttribute("state", null); // ???? //from ww w . jav a 2 s .c om response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "teacher_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("qq"); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue(""); cell.setCellStyle(style); List allteacher = TeacherDao.getAllTeacher(); for (int i = 0; i < allteacher.size(); i++) { TempTeacherWithoutPwd tmp = (TempTeacherWithoutPwd) allteacher.get(i); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(tmp.getTeacherSn()); row.createCell((short) 1).setCellValue(tmp.getTeacherName()); row.createCell((short) 2).setCellValue(tmp.getTeacherIdcard()); row.createCell((short) 3).setCellValue(tmp.getTeacherPosition()); row.createCell((short) 4).setCellValue(tmp.getTeacherCollege()); row.createCell((short) 5).setCellValue(tmp.getTeacherQq()); row.createCell((short) 6).setCellValue(tmp.getTeacherTel()); row.createCell((short) 7).setCellValue((tmp.getTeacherSex()) ? ("") : ("")); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); }
From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java
@RequestMapping("teacher/xz_xs_xx") public @ResponseBody String daochuxuesheng(HttpServletRequest request, HttpServletResponse response) throws IOException { int classid = Integer.parseInt(request.getParameter("zjd_id")); int course_id = Integer.parseInt(request.getParameter("fjd_id")); int term = Integer.parseInt(request.getParameter("term")); String sn = getCurrentUsername(); Teacher tec = TeacherDao.getTeacherBySn(sn); int tec_id = tec.getTeacherId(); int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id); System.out.println(trem_courseid + "trem_courseid"); PageBean<StuSelectResult> mystudent = TeacherDao.getStuSelectByTermCourseId(trem_courseid, 1, 300); HttpSession session = request.getSession(); session.setAttribute("state", null); // ???? //from ww w . j a v a 2 s .co m response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "student_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("qq"); cell.setCellStyle(style); for (int i = 0; i < mystudent.getBeanList().size(); i++) { StuSelectResult a = (StuSelectResult) mystudent.getBeanList().get(i); System.out.println(getStudentById(a.getStuid()).getStudentSn()); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(getStudentById(a.getStuid()).getStudentSn()); row.createCell((short) 1).setCellValue(getStudentById(a.getStuid()).getStudentName()); row.createCell((short) 2).setCellValue(getStudentById(a.getStuid()).getStudentIdcard()); row.createCell((short) 3).setCellValue(getStudentById(a.getStuid()).getStudentGrade()); row.createCell((short) 4) .setCellValue((getStudentById(a.getStuid()).getStudentSex()) ? ("") : ("")); row.createCell((short) 5).setCellValue(getStudentById(a.getStuid()).getStudentCollege()); row.createCell((short) 6).setCellValue(getStudentById(a.getStuid()).getStudentTel()); row.createCell((short) 7).setCellValue(getStudentById(a.getStuid()).getStudentQq()); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); return "1"; }
From source file:cn.edu.henu.rjxy.lms.controller.Tea_Controller.java
@RequestMapping("xz_xs_xx") public @ResponseBody String daochuxuesheng(HttpServletRequest request, HttpServletResponse response) throws IOException { int classid = Integer.parseInt(request.getParameter("zjd_id")); int course_id = Integer.parseInt(request.getParameter("fjd_id")); int term = Integer.parseInt(request.getParameter("term")); String sn = getCurrentUsername(); Teacher tec = TeacherDao.getTeacherBySn(sn); int tec_id = tec.getTeacherId(); int trem_courseid = TermCourseDao.getTermCourseId(term, course_id, classid, tec_id); System.out.println(trem_courseid + "trem_courseid"); PageBean<StuSelectResult> mystudent = TeacherDao.getStuSelectByTermCourseId(trem_courseid, 1, 300); HttpSession session = request.getSession(); session.setAttribute("state", null); // ???? /* w w w. j a va 2 s . co m*/ response.setContentType("application/vnd.ms-excel"); String codedFileName; codedFileName = "??"; OutputStream fOut = null; try { // ???? codedFileName = java.net.URLEncoder.encode("", "UTF-8"); response.setHeader("content-disposition", "attachment;filename=" + "student_messsage" + ".xls"); HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet(""); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell((short) 0); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("qq"); cell.setCellStyle(style); for (int i = 0; i < mystudent.getBeanList().size(); i++) { StuSelectResult a = (StuSelectResult) mystudent.getBeanList().get(i); System.out.println(getStudentById(a.getStuid()).getStudentSn()); row = sheet.createRow((int) i + 1); row.createCell((short) 0).setCellValue(getStudentById(a.getStuid()).getStudentSn()); row.createCell((short) 1).setCellValue(getStudentById(a.getStuid()).getStudentName()); row.createCell((short) 2).setCellValue(getStudentById(a.getStuid()).getStudentIdcard()); row.createCell((short) 3).setCellValue(getStudentById(a.getStuid()).getStudentGrade()); row.createCell((short) 4) .setCellValue((getStudentById(a.getStuid()).getStudentSex()) ? ("") : ("")); row.createCell((short) 5).setCellValue(getStudentById(a.getStuid()).getStudentCollege()); row.createCell((short) 6).setCellValue(getStudentById(a.getStuid()).getStudentTel()); row.createCell((short) 7).setCellValue(getStudentById(a.getStuid()).getStudentQq()); } fOut = response.getOutputStream(); wb.write(fOut); } catch (UnsupportedEncodingException e1) { } catch (Exception e) { } finally { fOut.flush(); fOut.close(); session.setAttribute("state", "open"); } System.out.println("?..."); return "1"; }
From source file:cn.edu.zju.acm.onlinejudge.action.ShowRankListAction.java
License:Open Source License
private byte[] exportToExcel(AbstractContest contest, List<Problem> problems, RankList ranklist) throws Exception { List<RankListEntry> entries = ranklist.getEntries(); long time = this.getTimeEscaped(contest); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet();// w w w. jav a 2 s . c o m HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell((short) 0); cell.setCellValue(contest.getTitle()); if (ranklist.getRole() != null) { row = sheet.createRow(1); cell = row.createCell((short) 0); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(ranklist.getRole().getDescription()); } row = sheet.createRow(2); cell = row.createCell((short) 0); cell.setCellValue("Length"); cell = row.createCell((short) 1); cell.setCellValue(Utility.toTime(contest.getLength() / 1000)); row = sheet.createRow(3); cell = row.createCell((short) 0); cell.setCellValue("Time Escaped"); cell = row.createCell((short) 1); cell.setCellValue(Utility.toTime(time / 1000)); row = sheet.createRow(5); row.createCell((short) 0).setCellValue("Rank"); row.createCell((short) 1).setCellValue("Handle"); row.createCell((short) 2).setCellValue("Nickname"); row.createCell((short) 3).setCellValue("Solved"); short columnIndex = 4; for (Problem problem2 : problems) { Problem problem = problem2; row.createCell(columnIndex).setCellValue(problem.getCode()); columnIndex++; } row.createCell(columnIndex).setCellValue("Penalty"); int rowIndex = 6; for (RankListEntry rankListEntry : entries) { RankListEntry entry = rankListEntry; row = sheet.createRow(rowIndex); row.createCell((short) 0).setCellValue(rowIndex - 5); row.createCell((short) 1).setCellValue(entry.getUserProfile().getHandle()); String nick = entry.getUserProfile().getHandle(); if (entry.getUserProfile().getNickName() != null) { nick = entry.getUserProfile().getNickName(); } cell = row.createCell((short) 2); cell.setEncoding(HSSFCell.ENCODING_UTF_16); cell.setCellValue(nick); row.createCell((short) 3).setCellValue(entry.getSolved()); for (short i = 0; i < problems.size(); ++i) { String score = entry.getAcceptTime(i) > 0 ? entry.getAcceptTime(i) + "(" + entry.getSubmitNumber(i) + ")" : "" + entry.getSubmitNumber(i); row.createCell((short) (4 + i)).setCellValue(score); } row.createCell((short) (4 + problems.size())).setCellValue(entry.getPenalty()); rowIndex++; } // output to stream ByteArrayOutputStream out = new ByteArrayOutputStream(); try { wb.write(out); return out.toByteArray(); } finally { out.close(); } }
From source file:cn.edu.zju.acm.onlinejudge.action.UserSearchAction.java
License:Open Source License
private byte[] exportToExcel(UserCriteria criteria, List<UserProfile> users) throws Exception { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet();// w w w. j a v a 2 s . c o m short rowId = 0; for (Object user : users) { HSSFRow row = sheet.createRow(rowId); rowId++; HSSFCell cell = row.createCell((short) 0); cell.setCellValue(((UserProfile) user).getHandle()); } // output to stream ByteArrayOutputStream out = new ByteArrayOutputStream(); try { wb.write(out); return out.toByteArray(); } finally { out.close(); } }