List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook HSSFWorkbook
public HSSFWorkbook()
From source file:cn.com.zhbook.component.poi.PoiPerformanceTest.java
License:Apache License
static Workbook createWorkbook(String type) { if ("HSSF".equals(type)) return new HSSFWorkbook(); else if ("XSSF".equals(type)) return new XSSFWorkbook(); else if ("SXSSF".equals(type)) return new SXSSFWorkbook(); else/*from w ww .ja v a2s . c om*/ usage("Unknown type \"" + type + "\""); return null; }
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); // ???? /* w ww . j a v a2 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); // ???? //from w w w .j av a 2 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=" + "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 w w w . j ava2s . 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); // ???? //w w w . j a v 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=" + "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); // ???? /*from www .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.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 . j a va2 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();// ww w . j a va 2s . co 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(); } }
From source file:cn.mypandora.util.MyExcelUtil.java
License:Apache License
/** * Excel, ?//from ww w .ja v a2s.c om * * @param filepath ? * @param sheetTitle Sheet?? * @param fieldTitles Sheet???? */ public static void writeExcel(String filepath, String sheetTitle, String fieldTitles) { Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() }; for (int i = 0; i < wbs.length; i++) { Workbook wb = wbs[i]; // ExcelSheet Sheet sheet = wb.createSheet(); wb.setSheetName(0, sheetTitle); // Sheet createTitle(sheet, fieldTitles); // ?Excel saveExcelFile(wb, filepath); } }