List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook write
private void write(POIFSFileSystem fs) throws IOException
From source file:edu.swjtu.excel.ExportConCarData.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // webbookExcel HSSFWorkbook wb = new HSSFWorkbook(); // webbooksheet,Excelsheet HSSFSheet sheet = wb.createSheet("?"); // sheet0,??poiExcel?short HSSFRow row = sheet.createRow((int) 0); // ? /*from w w w.ja v a 2 s .c o m*/ HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // ? HSSFCell cell = row.createCell(0); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(3); cell.setCellValue(""); cell.setCellStyle(style); cell = row.createCell(4); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(5); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(6); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(7); cell.setCellValue("??"); cell.setCellStyle(style); cell = row.createCell(8); cell.setCellValue("?"); cell.setCellStyle(style); cell = row.createCell(9); cell.setCellValue("?"); cell.setCellStyle(style); // ? ?? Connection con = null; try { con = db.getCon(); } catch (ClassNotFoundException | SQLException e1) { e1.printStackTrace(); } String condition = request.getParameter("condition"); String sea_condition = request.getParameter("sea_condition"); String search_cho = null; ArrayList<Car> list = null; CarDaoImpl carr = new CarDaoImpl(); if (condition.equals("0")) { list = carr.getAllCar(con); search_cho = "All"; } else if (condition.equals("1")) { list = carr.getCarByLicensePlate_V(sea_condition, con); search_cho = "LicensePlate"; } else if (condition.equals("2")) { list = carr.getCarByBrand_V(sea_condition, con); search_cho = "Brand"; } else if (condition.equals("3")) { list = carr.getCarByDriver_V(sea_condition, con); search_cho = "Driver"; } else if (condition.equals("4")) { list = carr.getCarByArrangeId_V(sea_condition, con); search_cho = "ArrangeId"; } else if (condition.equals("5")) { list = carr.getCarByNumber_V(sea_condition, con); search_cho = "Number"; } else if (condition.equals("6")) { list = carr.getCarByDrivingLicense_V(sea_condition, con); search_cho = "DrivingLicenseber"; } else if (condition.equals("7")) { list = carr.getCarByLicense_V(sea_condition, con); search_cho = "License"; } else { } for (int i = 0; i < list.size(); i++) { row = sheet.createRow((int) i + 1); Car car = (Car) list.get(i); // ? row.createCell(0).setCellValue(i + 1); row.createCell(1).setCellValue(car.getLicensePlate()); row.createCell(2).setCellValue(car.getBrand()); row.createCell(3).setCellValue(car.getRegistrationDate()); row.createCell(4).setCellValue(car.getInsuranceDate()); row.createCell(5).setCellValue(car.getDrivingLicense()); row.createCell(6).setCellValue(car.getLicense()); row.createCell(7).setCellValue(car.getArrangeId()); row.createCell(8).setCellValue(car.getDriver()); row.createCell(9).setCellValue(car.getNumber()); } String myexcel = search_cho + "_Car"; //? OutputStream out = response.getOutputStream(); //?? response.reset(); //Excel? response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=" + myexcel + ".xls"); wb.write(out); out.close(); //? System.setOut(new PrintStream(out)); //? out.flush(); //? if (out != null) { out.close(); } try { db.closeCon(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.wisc.ssec.mcidasv.control.cyclone.StormDisplayState.java
License:Open Source License
/** * _more_//from w w w . ja v a2s .c o m */ public void writeToDataFile() { try { JComponent accessory = GuiUtils.top(GuiUtils.vbox(obsCbx, forecastCbx, mostRecentCbx, editedCbx)); String filename = FileManager.getWriteFile(Misc.newList(FileManager.FILTER_XLS, FILTER_DAT), FileManager.SUFFIX_XLS, accessory); if (filename == null) { return; } List<StormTrack> tracksToWrite = new ArrayList<StormTrack>(); List<Way> waysToUse = new ArrayList<Way>(); Hashtable<Way, List> trackMap = new Hashtable<Way, List>(); for (StormTrack track : trackCollection.getTracks()) { List tracks = trackMap.get(track.getWay()); if (tracks == null) { tracks = new ArrayList(); trackMap.put(track.getWay(), tracks); waysToUse.add(track.getWay()); } tracks.add(track); if (editedCbx.isSelected()) { if (track.getIsEdited()) { tracksToWrite.add(track); } } else { if (track.getWay().isObservation()) { if (obsCbx.isSelected()) { tracksToWrite.add(track); } } else { if (forecastCbx.isSelected()) { tracksToWrite.add(track); } } } } if (filename.endsWith(".dat")) { StringBuffer sb = StormTrack.toDiamond7(tracksToWrite, stormInfo.getStormId()); IOUtil.writeFile(filename, sb.toString()); return; } Hashtable sheetNames = new Hashtable(); HSSFWorkbook wb = new HSSFWorkbook(); StormTrack obsTrack = trackCollection.getObsTrack(); // Write the obs track first if ((obsTrack != null) && obsCbx.isSelected()) { write(wb, obsTrack, sheetNames); } if (forecastCbx.isSelected()) { waysToUse = Misc.sort(waysToUse); for (Way way : waysToUse) { if (way.isObservation()) { continue; } List<StormTrack> tracks = (List<StormTrack>) Misc.sort(trackMap.get(way)); if (mostRecentCbx.isSelected()) { write(wb, tracks.get(tracks.size() - 1), sheetNames); } else { for (StormTrack track : tracks) { write(wb, track, sheetNames); } } } } FileOutputStream fileOut = new FileOutputStream(filename); wb.write(fileOut); fileOut.close(); } catch (Exception exc) { stormTrackControl.logException("Writing spreadsheet", exc); } }
From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java
License:Apache License
/** * [Flow #-4] ? : ? ? ?(Header, Footer)? *///from w w w . j a va 2 s . c o m @Test public void testModifyDocAttribute() throws Exception { try { log.debug("testModifyDocAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyDocAttribute.xls"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); log.debug("Delete file...." + sb.toString()); } HSSFWorkbook wbTmp = new HSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? HSSFWorkbook wb = excelService.loadWorkbook(sb.toString()); log.debug("testModifyCellContents after loadWorkbook...."); HSSFSheet sheet = wb.createSheet("doc test sheet"); HSSFRow row = sheet.createRow(1); HSSFCell cell = row.createCell(1); cell.setCellValue(new HSSFRichTextString("Header/Footer Test")); // Header HSSFHeader header = sheet.getHeader(); header.setCenter("Center Header"); header.setLeft("Left Header"); header.setRight(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16) + "Right Stencil-Normal Italic font and size 16"); // Footer HSSFFooter footer = sheet.getFooter(); footer.setCenter(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -"); log.debug("Style is ... " + HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -"); footer.setLeft("Left Footer"); footer.setRight("Right Footer"); // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); assertTrue(EgovFileUtil.isExistsFile(sb.toString())); ////////////////////////////////////////////////////////////////////////// // ? HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString()); HSSFSheet sheetT = wbT.getSheet("doc test sheet"); HSSFHeader headerT = sheetT.getHeader(); assertEquals("Center Header", headerT.getCenter()); assertEquals("Left Header", headerT.getLeft()); assertEquals(HSSFHeader.font("Stencil-Normal", "Italic") + HSSFHeader.fontSize((short) 16) + "Right Stencil-Normal Italic font and size 16", headerT.getRight()); HSSFFooter footerT = sheetT.getFooter(); assertEquals("Right Footer", footerT.getRight()); assertEquals("Left Footer", footerT.getLeft()); assertEquals(HSSFHeader.font("Fixedsys", "Normal") + HSSFHeader.fontSize((short) 12) + "- 1 -", footerT.getCenter()); } catch (Exception e) { log.error(e.toString()); throw new Exception(e); } finally { log.debug("testModifyDocAttribute end...."); } }
From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java
License:Apache License
/** * [Flow #-5] : ?? ? ? ? //from ww w .ja v a 2 s.c o m */ @Test public void testGetCellContents() throws Exception { try { log.debug("testGetCellContents start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testGetCellContents.xls"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); log.debug("Delete file...." + sb.toString()); } HSSFWorkbook wbTmp = new HSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? HSSFWorkbook wb = excelService.loadWorkbook(sb.toString()); log.debug("testGetCellContents after loadWorkbook...."); HSSFSheet sheet = wb.createSheet("cell test sheet"); HSSFCellStyle cs = wb.createCellStyle(); cs = wb.createCellStyle(); cs.setWrapText(true); for (int i = 0; i < 100; i++) { HSSFRow row = sheet.createRow(i); for (int j = 0; j < 5; j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(new HSSFRichTextString("row " + i + ", cell " + j)); cell.setCellStyle(cs); } } // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); ////////////////////////////////////////////////////////////////////////// // ? HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString()); HSSFSheet sheetT = wbT.getSheet("cell test sheet"); for (int i = 0; i < 100; i++) { HSSFRow row1 = sheetT.getRow(i); for (int j = 0; j < 5; j++) { HSSFCell cell1 = row1.getCell(j); log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue()); assertEquals("row " + i + ", cell " + j, cell1.getRichStringCellValue().toString()); } } } catch (Exception e) { log.error(e.toString()); throw new Exception(e); } finally { log.debug("testGetCellContents end...."); } }
From source file:egovframework.rte.fdl.excel.EgovExcelSXSSFServiceTest.java
License:Apache License
/** * [Flow #-6] ? : ? ?(?, ? )? /* w w w . ja v a 2 s .c o m*/ */ @Test public void testModifyCellAttribute() throws Exception { try { log.debug("testModifyCellAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyCellAttribute.xls"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); log.debug("Delete file...." + sb.toString()); } HSSFWorkbook wbTmp = new HSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? HSSFWorkbook wb = excelService.loadWorkbook(sb.toString()); log.debug("testModifyCellAttribute after loadWorkbook...."); HSSFSheet sheet = wb.createSheet("cell test sheet2"); // sheet.setColumnWidth((short) 3, (short) 200); // column Width HSSFCellStyle cs = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setFontHeight((short) 16); font.setBoldweight((short) 3); font.setFontName("fixedsys"); cs.setFont(font); cs.setAlignment(HSSFCellStyle.ALIGN_RIGHT); // cell cs.setWrapText(true); for (int i = 0; i < 100; i++) { HSSFRow row = sheet.createRow(i); // row.setHeight((short)300); // row? height for (int j = 0; j < 5; j++) { HSSFCell cell = row.createCell(j); cell.setCellValue(new HSSFRichTextString("row " + i + ", cell " + j)); cell.setCellStyle(cs); } } // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); ////////////////////////////////////////////////////////////////////////// // ? HSSFWorkbook wbT = excelService.loadWorkbook(sb.toString()); HSSFSheet sheetT = wbT.getSheet("cell test sheet2"); log.debug("getNumCellStyles : " + wbT.getNumCellStyles()); HSSFCellStyle cs1 = wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1)); HSSFFont fontT = cs1.getFont(wbT); log.debug("font getFontHeight : " + fontT.getFontHeight()); log.debug("font getBoldweight : " + fontT.getBoldweight()); log.debug("font getFontName : " + fontT.getFontName()); log.debug("getAlignment : " + cs1.getAlignment()); log.debug("getWrapText : " + cs1.getWrapText()); for (int i = 0; i < 100; i++) { HSSFRow row1 = sheetT.getRow(i); for (int j = 0; j < 5; j++) { HSSFCell cell1 = row1.getCell(j); log.debug("row " + i + ", cell " + j + " : " + cell1.getRichStringCellValue()); assertEquals(16, fontT.getFontHeight()); assertEquals(3, fontT.getBoldweight()); assertEquals(HSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment()); assertTrue(cs1.getWrapText()); } } } catch (Exception e) { log.error(e.toString()); throw new Exception(e); } finally { log.debug("testModifyCellAttribute end...."); } }
From source file:eionet.cr.util.export.XlsExporter.java
License:Mozilla Public License
/** * exports custom search to XLS format.//from ww w.j av a 2s . c om * * @param customSearch * @return * @throws IOException * @throws DAOException */ protected InputStream doExport() throws IOException, DAOException { HSSFWorkbook workbook = new HSSFWorkbook(); sheet = workbook.createSheet("exported data"); // some pretty print with headers CellStyle headerStyle = workbook.createCellStyle(); Font headerFont = workbook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); headerStyle.setFont(headerFont); // output headers HSSFRow headers = sheet.createRow(0); // store width of each column +1 for Uri or Label column columnWidth = new int[getSelectedColumns().size() + 1]; // output Uri or Label column String uriOrLabelColumn = getUriOrLabel(); columnWidth[0] = uriOrLabelColumn.length(); HSSFCell uriOrLabelCell = headers.createCell(0); XlsUtil.setCellValue(uriOrLabelCell, uriOrLabelColumn); uriOrLabelCell.setCellStyle(headerStyle); // output rest of the headers int columnNumber = 1; for (Pair<String, String> columnPair : getSelectedColumns()) { // label is already added to the list of elements if (Predicates.RDFS_LABEL.equals(columnPair.getLeft())) continue; String column = columnPair.getRight() != null ? columnPair.getRight() : columnPair.getLeft(); columnWidth[columnNumber] = column.length(); HSSFCell cell = headers.createCell(columnNumber++); XlsUtil.setCellValue(cell, column); cell.setCellStyle(headerStyle); } sheet.createFreezePane(0, 1); // output serarch results SubjectExportReader reader = new SubjectExportReader(this); doExportQueryAndWriteDataIntoOutput(reader); // set column width for (int i = 0; i < getSelectedColumns().size() + 1; i++) { sheet.setColumnWidth(i, Math.min(256 * columnWidth[i], 256 * 255)); } ByteArrayOutputStream output = new ByteArrayOutputStream(); workbook.write(output); return new ByteArrayInputStream(output.toByteArray()); }
From source file:es.jamisoft.comun.io.excel.ExcelGenerator.java
License:Apache License
/** * Es el mtodo principal del componente y gestiona la creacin del fichero. * * @param data Coleccin con la que se desea crear el fichero Excel. * @param mapColumns Mapa con la relacin de los elementos de la coleccin que * se desean mostrar y el titulo que tendrn las cabeceras. * * Por ejemplo:/*from w w w. j av a2s . c o m*/ * String mapColumns = "dni=DNI;nombre=NOMBRE;apellidos=APELLIDO"; * * donde: * dni, nombre y apellidos, serian elementos de la coleccin. * * y: * DNI, NOMBRE y APELLIDO, serian los ttulos de las cabeceras. * * @return Devuelve un objeto ByteArrayOutputStream. */ public ByteArrayOutputStream createExcelFile(List<?> data, String mapColumns) { HSSFWorkbook wb = new HSSFWorkbook(); List<Header> columns = new ArrayList<Header>(); initStylesHeader(wb); initStylesBody(wb); List<List<?>> elements = createElementsForPages(data); if (StringUtils.hasText(mapColumns)) { columns = createHeader(mapColumns); } else { columns = createHeader(data.get(0)); } Map<String, Method> getterMethods = initMappings(data.get(0), columns); Iterator<List<?>> pagesIterator = elements.iterator(); int pageNumber = 0; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { while (pagesIterator.hasNext()) { procesPage(pagesIterator.next(), wb, columns, getterMethods, pageNumber++); } wb.write(baos); } catch (Throwable e) { logger.error(e); } return baos; }
From source file:esd.common.PoiCreateExcel.java
License:Open Source License
/** * ???/*w ww. j a v a 2 s . c o m*/ * * @param FilePath * @param jobList * @return */ public static boolean createJobExcel(String FilePath, List<Job> jobList) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("????"); headell = headRow.createCell(1); headell.setCellValue("?"); headell = headRow.createCell(2); headell.setCellValue(""); headell = headRow.createCell(3); headell.setCellValue(""); headell = headRow.createCell(4); headell.setCellValue("???"); headell = headRow.createCell(5); headell.setCellValue(""); headell = headRow.createCell(6); headell.setCellValue("?"); headell = headRow.createCell(7); headell.setCellValue("???"); headell = headRow.createCell(8); headell.setCellValue("?"); headell = headRow.createCell(9); headell.setCellValue("?"); headell = headRow.createCell(10); headell.setCellValue("??"); headell = headRow.createCell(11); headell.setCellValue("?"); headell = headRow.createCell(12); headell.setCellValue("?"); headell = headRow.createCell(13); headell.setCellValue("??"); headell = headRow.createCell(14); headell.setCellValue(""); headell = headRow.createCell(15); headell.setCellValue("? "); headell = headRow.createCell(16); headell.setCellValue("?"); headell = headRow.createCell(17); headell.setCellValue(""); headell = headRow.createCell(18); headell.setCellValue("????"); headell = headRow.createCell(19); headell.setCellValue("????"); headell = headRow.createCell(20); headell.setCellValue("?/?"); headell = headRow.createCell(21); headell.setCellValue(""); headell = headRow.createCell(22); headell.setCellValue("?"); headell = headRow.createCell(23); headell.setCellValue("??"); headell = headRow.createCell(24); headell.setCellValue("??"); for (int i = 1; i <= jobList.size(); i++) { Job job = jobList.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? cell = row.createCell(0); cell.setCellValue(job.getName()); cell = row.createCell(1); cell.setCellValue(job.getHireNumber()); cell = row.createCell(2); cell.setCellValue(job.getSalary()); cell = row.createCell(3); cell.setCellValue(job.getEducation()); cell = row.createCell(4); cell.setCellValue(job.getExperience()); cell = row.createCell(5); cell.setCellValue(job.getGender()); cell = row.createCell(6); cell.setCellValue(job.getAge()); cell = row.createCell(7); cell.setCellValue(job.getDescription()); cell = row.createCell(8); cell.setCellValue(job.getProvideBenefit()); cell = row.createCell(9); cell.setCellValue(job.getContactPerson()); cell = row.createCell(10); cell.setCellValue(job.getContactTel()); cell = row.createCell(11); cell.setCellValue(job.getContactEmail()); if (job.getViewCount() != null) { cell = row.createCell(12); cell.setCellValue(job.getViewCount()); } cell = row.createCell(13); cell.setCellValue(job.getNature()); cell = row.createCell(14); cell.setCellValue(job.getEffectiveDays()); cell = row.createCell(15); // cell.setCellValue(job.getIsActiveEffectiveTime()); if (job.getEffectiveTime() != null) { SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // ?? String effectiveTimeString = dateFm.format(job.getEffectiveTime()); cell = row.createCell(16); cell.setCellValue(effectiveTimeString); } if (job.getWorkPlace() != null) { if (job.getWorkPlace().getCode() != null && !"".equals(job.getWorkPlace().getCode())) { cell = row.createCell(17); cell.setCellValue(job.getWorkPlace().getName()); } } if (job.isBed() == true) { cell = row.createCell(18); cell.setCellValue(""); } else if (job.isBed() == false) { cell = row.createCell(18); cell.setCellValue("?"); } if (job.isLunch() == true) { cell = row.createCell(19); cell.setCellValue(""); } else if (job.isLunch() == false) { cell = row.createCell(19); cell.setCellValue("?"); } cell = row.createCell(20); cell.setCellValue(job.getCheckStatus()); cell = row.createCell(21); cell.setCellValue(job.getMark()); if (job.getCompany() != null) { cell = row.createCell(22); cell.setCellValue(job.getCompany().getName()); } if (job.getArea() != null) { if (job.getArea().getCode() != null && !"".equals(job.getArea().getCode())) { cell = row.createCell(23); cell.setCellValue(job.getArea().getName()); } } if (job.getJobCategory() != null) { if (job.getJobCategory().getCode() != null && !"".equals(job.getJobCategory().getCode())) { cell = row.createCell(24); cell.setCellValue(job.getJobCategory().getName()); } } } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); jobList.clear(); jobList = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:esd.common.PoiCreateExcel.java
License:Open Source License
/** * ???/*w w w .j a va2s . co m*/ * * @param FilePath * @param companyList * @return */ public static boolean createComapnyExcel(String FilePath, List<Company> companyList) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("???"); headell = headRow.createCell(1); headell.setCellValue(""); headell = headRow.createCell(2); headell.setCellValue("?"); headell = headRow.createCell(3); headell.setCellValue("??"); headell = headRow.createCell(4); headell.setCellValue("?"); headell = headRow.createCell(5); headell.setCellValue(""); headell = headRow.createCell(6); headell.setCellValue("?"); headell = headRow.createCell(7); headell.setCellValue("??"); headell = headRow.createCell(8); headell.setCellValue("?"); headell = headRow.createCell(9); headell.setCellValue("?"); headell = headRow.createCell(10); headell.setCellValue("??"); headell = headRow.createCell(11); headell.setCellValue("?"); headell = headRow.createCell(12); headell.setCellValue("???"); headell = headRow.createCell(13); headell.setCellValue("ID"); headell = headRow.createCell(14); headell.setCellValue("?"); headell = headRow.createCell(15); headell.setCellValue("?"); headell = headRow.createCell(16); headell.setCellValue("?"); headell = headRow.createCell(17); headell.setCellValue(" ?"); headell = headRow.createCell(18); headell.setCellValue(""); headell = headRow.createCell(19); headell.setCellValue("?"); // headell = headRow.createCell(20); // headell.setCellValue("?"); for (int i = 1; i <= companyList.size(); i++) { Company company = companyList.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? // ??? cell = row.createCell(0); cell.setCellValue(company.getName()); // cell = row.createCell(1); cell.setCellValue(company.getCorporateRepresentative()); // ? cell = row.createCell(2); cell.setCellValue(company.getContactPerson()); // ?? cell = row.createCell(3); cell.setCellValue(company.getTelephone()); // ? cell = row.createCell(4); cell.setCellValue(company.getContactDept()); // cell = row.createCell(5); cell.setCellValue(company.getFax()); // ? cell = row.createCell(6); cell.setCellValue(company.getEmail()); // ?? cell = row.createCell(7); cell.setCellValue(company.getAddress()); // ? cell = row.createCell(8); cell.setCellValue(company.getIntroduction()); // ? cell = row.createCell(9); cell.setCellValue(company.getOrganizationCode()); // ?? cell = row.createCell(10); cell.setCellValue(company.getCommercialCode()); // ? cell = row.createCell(11); cell.setCellValue(company.getTaxCode()); // ??? cell = row.createCell(12); cell.setCellValue(company.getSocialSecurityCode()); // ID cell = row.createCell(13); cell.setCellValue(company.getWebSiteId()); // ? cell = row.createCell(14); cell.setCellValue(company.getLaoWangCode()); // ? cell = row.createCell(15); cell.setCellValue(company.getScale()); // ? cell = row.createCell(16); cell.setCellValue(company.getNature()); // ? cell = row.createCell(17); cell.setCellValue(company.getEconomyType()); // cell = row.createCell(18); cell.setCellValue(company.getRemark()); // ? if (company.getViewCount() != null) { cell = row.createCell(19); cell.setCellValue(company.getViewCount()); } // cell = row.createCell(20); // cell.setCellValue(company.getCheckStatus()); } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); companyList.clear(); companyList = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:esd.common.PoiCreateExcel.java
License:Open Source License
/** * ?/* ww w . ja v a 2s . c o m*/ * * @param FilePath * @param resumeList * @return */ public static boolean createResumeExcel(String FilePath, List<Resume> resumeList) { // Excel Workbook,excel HSSFWorkbook wb = new HSSFWorkbook(); // Excelsheet,exceltab HSSFSheet sheet = wb.createSheet("sheet1"); // excel? sheet.setColumnWidth(0, 4000); sheet.setColumnWidth(1, 3500); // Excel? HSSFRow headRow = sheet.createRow(0); HSSFCell headell = headRow.createCell(0); // ??? headell = headRow.createCell(0); headell.setCellValue("??"); headell = headRow.createCell(1); headell.setCellValue("??"); headell = headRow.createCell(2); headell.setCellValue(""); headell = headRow.createCell(3); headell.setCellValue(""); headell = headRow.createCell(4); headell.setCellValue("??"); headell = headRow.createCell(5); headell.setCellValue("?"); headell = headRow.createCell(6); headell.setCellValue(""); headell = headRow.createCell(7); headell.setCellValue("?"); headell = headRow.createCell(8); headell.setCellValue("??"); headell = headRow.createCell(9); headell.setCellValue("?"); headell = headRow.createCell(10); headell.setCellValue("??"); headell = headRow.createCell(11); headell.setCellValue("?"); headell = headRow.createCell(12); headell.setCellValue("?"); headell = headRow.createCell(13); headell.setCellValue("?"); headell = headRow.createCell(14); headell.setCellValue("QQ??"); headell = headRow.createCell(15); headell.setCellValue(""); headell = headRow.createCell(16); headell.setCellValue("??"); headell = headRow.createCell(17); headell.setCellValue(" "); headell = headRow.createCell(18); headell.setCellValue("?"); headell = headRow.createCell(19); headell.setCellValue(""); headell = headRow.createCell(20); headell.setCellValue("?"); headell = headRow.createCell(21); headell.setCellValue("?"); headell = headRow.createCell(22); headell.setCellValue(""); headell = headRow.createCell(23); headell.setCellValue(" cm"); headell = headRow.createCell(24); headell.setCellValue("? kg"); headell = headRow.createCell(25); headell.setCellValue(""); headell = headRow.createCell(26); headell.setCellValue(""); headell = headRow.createCell(27); headell.setCellValue(""); headell = headRow.createCell(28); headell.setCellValue("?"); headell = headRow.createCell(29); headell.setCellValue("?"); headell = headRow.createCell(30); headell.setCellValue("? ?"); headell = headRow.createCell(31); headell.setCellValue(""); headell = headRow.createCell(32); headell.setCellValue(""); headell = headRow.createCell(33); headell.setCellValue("?"); headell = headRow.createCell(34); headell.setCellValue("?"); headell = headRow.createCell(35); headell.setCellValue("/?"); headell = headRow.createCell(36); headell.setCellValue(""); headell = headRow.createCell(37); headell.setCellValue(""); headell = headRow.createCell(38); headell.setCellValue("??"); headell = headRow.createCell(39); headell.setCellValue(""); headell = headRow.createCell(40); headell.setCellValue(""); headell = headRow.createCell(41); headell.setCellValue("???"); headell = headRow.createCell(42); headell.setCellValue("????"); headell = headRow.createCell(43); headell.setCellValue("???"); headell = headRow.createCell(44); headell.setCellValue("???"); headell = headRow.createCell(45); headell.setCellValue(""); headell = headRow.createCell(46); headell.setCellValue("???"); headell = headRow.createCell(47); headell.setCellValue("??"); headell = headRow.createCell(48); headell.setCellValue("??"); headell = headRow.createCell(49); headell.setCellValue(""); headell = headRow.createCell(50); headell.setCellValue("?"); headell = headRow.createCell(51); headell.setCellValue("?"); for (int i = 1; i <= resumeList.size(); i++) { Resume resume = resumeList.get(i - 1); // Excel? HSSFRow row = sheet.createRow(i); HSSFCell cell = row.createCell(0); // ??? cell = row.createCell(0); cell.setCellValue(resume.getTitle()); cell = row.createCell(1); cell.setCellValue(resume.getName()); cell = row.createCell(2); cell.setCellValue(resume.getGender()); cell = row.createCell(3); cell.setCellValue(resume.getBirth()); cell = row.createCell(4); cell.setCellValue(resume.getIdentityCard()); cell = row.createCell(5); cell.setCellValue(resume.getRace()); cell = row.createCell(6); cell.setCellValue(resume.getMarriage()); if (resume.getHukou() != null) { if (resume.getHukou().getCode() != null && !"".equals(resume.getHukou().getCode())) { cell = row.createCell(7); cell.setCellValue(resume.getHukou().getName()); } } cell = row.createCell(8); cell.setCellValue(resume.getHukouAddress()); cell = row.createCell(9); cell.setCellValue(resume.getHukouStatus()); cell = row.createCell(10); cell.setCellValue(resume.getAddress()); cell = row.createCell(11); cell.setCellValue(resume.getZipcode()); cell = row.createCell(12); cell.setCellValue(resume.getPhone()); cell = row.createCell(13); cell.setCellValue(resume.getEmail()); cell = row.createCell(14); cell.setCellValue(resume.getQq()); cell = row.createCell(15); cell.setCellValue(resume.getDisabilityCategory()); cell = row.createCell(16); cell.setCellValue(resume.getDisabilityCard()); cell = row.createCell(17); cell.setCellValue(resume.getDisabilityLevel()); cell = row.createCell(18); cell.setCellValue(resume.getDisabilityPart()); cell = row.createCell(19); cell.setCellValue(resume.getWorkAbility()); cell = row.createCell(20); cell.setCellValue(resume.getHomeTown()); cell = row.createCell(21); cell.setCellValue(resume.getPoliticalStatus()); cell = row.createCell(22); cell.setCellValue(resume.getAge()); cell = row.createCell(23); cell.setCellValue(resume.getHeight()); cell = row.createCell(24); cell.setCellValue(resume.getWeight()); cell = row.createCell(25); cell.setCellValue(resume.getProcessState()); cell = row.createCell(26); cell.setCellValue(resume.getEducation()); cell = row.createCell(27); cell.setCellValue(resume.getMajor()); cell = row.createCell(28); cell.setCellValue(resume.getSchool()); cell = row.createCell(29); cell.setCellValue(resume.getZhiCheng()); cell = row.createCell(30); cell.setCellValue(resume.getShiYeHao()); cell = row.createCell(31); cell.setCellValue(resume.getExperts()); cell = row.createCell(32); cell.setCellValue(resume.getTraining()); cell = row.createCell(33); cell.setCellValue(resume.getExperience()); cell = row.createCell(34); cell.setCellValue(resume.getWorkExperience()); cell = row.createCell(35); cell.setCellValue(resume.getSelfEvaluation()); cell = row.createCell(36); cell.setCellValue(resume.getAttachment()); cell = row.createCell(37); cell.setCellValue(resume.getJobNature()); if (resume.getDesireJob() != null) { if (resume.getDesireJob().getCode() != null && !"".equals(resume.getDesireJob().getCode())) { cell = row.createCell(38); log.info(resume.getDesireJob().getName() + "********8"); cell.setCellValue(resume.getDesireJob().getName()); } } if (resume.getDesireAddress() != null) { if (resume.getDesireAddress().getCode() != null && !"".equals(resume.getDesireAddress().getCode())) { cell = row.createCell(39); cell.setCellValue(resume.getDesireAddress().getName()); } } cell = row.createCell(40); cell.setCellValue(resume.getDesireSalary()); if (resume.isProvideFoodAndRoom() == true) { cell = row.createCell(41); cell.setCellValue(""); } else if (resume.isProvideFoodAndRoom() == false) { cell = row.createCell(41); cell.setCellValue("?"); } if (resume.isProvideRoom() == true) { cell = row.createCell(42); cell.setCellValue(""); } else if (resume.isProvideRoom() == false) { cell = row.createCell(42); cell.setCellValue("?"); } if (resume.isProvideFood() == true) { cell = row.createCell(43); cell.setCellValue(""); } else if (resume.isProvideFood() == false) { cell = row.createCell(43); cell.setCellValue("?"); } if (resume.isProvideInsurance() == true) { cell = row.createCell(44); cell.setCellValue(""); } else if (resume.isProvideInsurance() == false) { cell = row.createCell(44); cell.setCellValue("?"); } cell = row.createCell(45); cell.setCellValue(resume.getProvideOther()); if (resume.isWorkShift() == true) { cell = row.createCell(46); cell.setCellValue(""); } else if (resume.isWorkShift() == false) { cell = row.createCell(46); cell.setCellValue("?"); } cell = row.createCell(47); cell.setCellValue(resume.getState()); if (resume.getIsDefault() == true) { cell = row.createCell(48); cell.setCellValue(""); } else if (resume.getIsDefault() == false) { cell = row.createCell(48); cell.setCellValue("?"); } cell = row.createCell(49); cell.setCellValue(resume.getCheckStatus()); if (resume.getViewCount() != null) { cell = row.createCell(50); cell.setCellValue(resume.getViewCount()); } cell = row.createCell(51); cell.setCellValue(resume.getCareerTest()); } try { FileOutputStream os = new FileOutputStream(FilePath); wb.write(os); os.flush(); os.close(); resumeList.clear(); resumeList = null; os = null; wb = null; System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }