List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet
Sheet createSheet(String sheetname);
From source file:edu.jhu.jmontan.hw5.CostAsExcelServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j ava2s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); LineItemReceipt receipt = (LineItemReceipt) session.getAttribute("receipt"); response.setHeader("content-disposition", "attachment; filename=hopkinscost.xls"); response.setHeader("cache-control", "no-cache"); try (OutputStream out = response.getOutputStream()) { int rowNum = 0; Workbook workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet("Conference Cost"); Row row = sheet.createRow(rowNum); row.createCell(0).setCellValue("Course"); row.createCell(1).setCellValue("Cost"); rowNum++; for (LineItem lineItem : receipt.getLineItems()) { int cost = lineItem.getCost(); String name = lineItem.getName(); row = sheet.createRow(rowNum); row.createCell(0).setCellValue(name); row.createCell(1).setCellValue(cost); rowNum++; } row = sheet.createRow(rowNum); row.createCell(0).setCellValue("Total"); row.createCell(1).setCellValue(receipt.getTotal()); workbook.write(out); } }
From source file:egovframework.rte.fdl.excel.EgovExcelServiceTest.java
License:Apache License
/** * [Flow #-1] ? ? : ?? ?/* w ww . j av a2s.com*/ */ @Test public void testWriteExcelFile() throws Exception { try { LOGGER.debug("testWriteExcelFile start...."); String sheetName1 = "first sheet"; String sheetName2 = "second sheet"; StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testWriteExcelFile.xls"); // delete file if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file...." + sb.toString()); } Workbook wb = new HSSFWorkbook(); wb.createSheet(sheetName1); wb.createSheet(sheetName2); wb.createSheet(); // ? ? Workbook tmp = excelService.createWorkbook(wb, sb.toString()); // ? ? assertTrue(EgovFileUtil.isExistsFile(sb.toString())); // ? Sheet ? ? assertEquals(sheetName1, tmp.getSheetName(0)); assertEquals(sheetName2, tmp.getSheetName(1)); } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testWriteExcelFile end...."); } }
From source file:egovframework.rte.fdl.excel.EgovExcelServiceTest.java
License:Apache License
/** * [Flow #-3] ? ? : ?? ?(? ?, Border? ?, ? ?, )? *///from w w w.ja v a 2 s.c om @Test public void testWriteExcelFileAttribute() throws Exception { try { LOGGER.debug("testWriteExcelFileAttribute start...."); short rowheight = 40 * 10; int columnwidth = 30; StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testWriteExcelFileAttribute.xls"); // delete file if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } Workbook wb = new HSSFWorkbook(); Sheet sheet1 = wb.createSheet("new sheet"); wb.createSheet("second sheet"); // ? ? sheet1.setDefaultRowHeight(rowheight); sheet1.setDefaultColumnWidth(columnwidth); Font f2 = wb.createFont(); CellStyle cs = wb.createCellStyle(); cs = wb.createCellStyle(); cs.setFont(f2); cs.setWrapText(true); // cs.setAlignment(CellStyle.ALIGN_RIGHT); cs.setFillPattern(CellStyle.DIAMONDS); // ? // ? ? cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); // cs.setFillBackgroundColor(new HSSFColor.RED().getIndex()); // sheet1.setDefaultColumnStyle((short) 0, cs); Workbook tmp = excelService.createWorkbook(wb, sb.toString()); Sheet sheetTmp1 = tmp.getSheetAt(0); assertEquals(rowheight, sheetTmp1.getDefaultRowHeight()); assertEquals(columnwidth, sheetTmp1.getDefaultColumnWidth()); CellStyle cs1 = tmp.getCellStyleAt((short) (tmp.getNumCellStyles() - 1)); LOGGER.debug("getAlignment : {}", cs1.getAlignment()); assertEquals(CellStyle.ALIGN_RIGHT, cs1.getAlignment()); LOGGER.debug("getFillPattern : {}", cs1.getFillPattern()); assertEquals(CellStyle.DIAMONDS, cs1.getFillPattern()); LOGGER.debug("getFillForegroundColor : {}", cs1.getFillForegroundColor()); LOGGER.debug("getFillBackgroundColor : {}", cs1.getFillBackgroundColor()); assertEquals(new HSSFColor.BLUE().getIndex(), cs1.getFillForegroundColor()); assertEquals(new HSSFColor.RED().getIndex(), cs1.getFillBackgroundColor()); } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testWriteExcelFileAttribute end...."); } }
From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java
License:Apache License
/** * [Flow #-1] ? ? : ?? ?/* w w w . j a va2 s . c om*/ */ @Test public void testWriteExcelFile() throws Exception { try { LOGGER.debug("testWriteExcelFile start...."); String sheetName1 = "first sheet"; String sheetName2 = "second sheet"; StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testWriteExcelFile.xlsx"); // delete file if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } Workbook wb = new XSSFWorkbook(); wb.createSheet(sheetName1); wb.createSheet(sheetName2); wb.createSheet(); // ? ? Workbook tmp = excelService.createWorkbook(wb, sb.toString()); // ? ? assertTrue(EgovFileUtil.isExistsFile(sb.toString())); // ? Sheet ? ? assertEquals(sheetName1, tmp.getSheetName(0)); assertEquals(sheetName2, tmp.getSheetName(1)); } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testWriteExcelFile end...."); } }
From source file:eleanalysis.SampleLibrary.java
/** * writes a report in the form of an excel spreadsheet that is exported. * Stage variable is for using a filechooser to pick where to save file. * @param myStage Stage is for saving file using FileChooser * @throws FileNotFoundException /*from w w w . j a va 2s.co m*/ */ public void writeReport(Stage myStage) throws FileNotFoundException { FileChooser pickFile = new FileChooser(); pickFile.setInitialDirectory(new File("C:\\Users\\Yan\\Documents\\NetBeansProjects\\EleAnalysis\\")); pickFile.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("XLS", "*.xls"), new FileChooser.ExtensionFilter("XLSX", "*.xlsx")); File writeFile = pickFile.showSaveDialog(myStage); FileOutputStream fileOut; fileOut = new FileOutputStream(writeFile); Workbook wb = new HSSFWorkbook(); Sheet sheet1 = wb.createSheet("WDXRF"); sheet1.setDefaultColumnWidth(15); // Create a cell space for (int i = 0; i < ElementUtils.skf.length + 5; i++) { Row tempR = sheet1.createRow(i); for (int j = 0; j <= array.size(); j++) { Cell tempC = tempR.createCell(j); } } CellStyle csCenter = wb.createCellStyle(); csCenter.setAlignment(CellStyle.ALIGN_CENTER); csCenter.setBorderTop(CellStyle.BORDER_THIN); csCenter.setBorderLeft(CellStyle.BORDER_THIN); csCenter.setBorderRight(CellStyle.BORDER_THIN); csCenter.setBorderBottom(CellStyle.BORDER_THIN); CellStyle csRight = wb.createCellStyle(); csRight.setAlignment(CellStyle.ALIGN_RIGHT); csRight.setBorderTop(CellStyle.BORDER_THIN); csRight.setBorderLeft(CellStyle.BORDER_THIN); csRight.setBorderRight(CellStyle.BORDER_THIN); csRight.setBorderBottom(CellStyle.BORDER_THIN); CellStyle csLeft = wb.createCellStyle(); csLeft.setAlignment(CellStyle.ALIGN_LEFT); csLeft.setBorderTop(CellStyle.BORDER_THIN); csLeft.setBorderLeft(CellStyle.BORDER_THIN); csLeft.setBorderRight(CellStyle.BORDER_THIN); csLeft.setBorderBottom(CellStyle.BORDER_THIN); //Top Row sheet1.getRow(0).setHeightInPoints(25); sheet1.addMergedRegion(new CellRangeAddress(0, 0, 0, array.size())); sheet1.getRow(0).getCell(0).setCellValue("WDXRF Analysis"); sheet1.getRow(0).getCell(0).setCellStyle(csCenter); sheet1.addMergedRegion(new CellRangeAddress(1, 1, 0, array.size())); //Second Row sheet1.getRow(1).getCell(0).setCellValue("Conc as Wt%"); sheet1.getRow(1).getCell(0).setCellStyle(csCenter); // Third Row sheet1.getRow(2).setHeightInPoints(35); sheet1.getRow(2).getCell(0).setCellValue("Common Oxides/Oxication States"); sheet1.getRow(2).getCell(0).setCellStyle(csLeft); for (int j = 1; j <= array.size(); j++) { sheet1.getRow(2).getCell(j).setCellStyle(csLeft); sheet1.getRow(2).getCell(j).setCellValue(array.get(j - 1).getName()); } //Fourth Row sheet1.getRow(3).getCell(0).setCellValue("% Detectable"); sheet1.getRow(3).getCell(0).setCellStyle(csLeft); for (int j = 1; j <= array.size(); j++) { sheet1.getRow(3).getCell(j).setCellValue("0.00"); sheet1.getRow(3).getCell(j).setCellStyle(csLeft); } //Fifth Row sheet1.addMergedRegion(new CellRangeAddress(4, 4, 0, array.size())); sheet1.getRow(4).getCell(0).setCellValue("Results Normalized with Respect to Detectable Concentration"); sheet1.getRow(4).getCell(0).setCellStyle(csCenter); //Rows 6 and beyond. Prints element list and defaults values to 0 for (int i = 5; i < ElementUtils.skf.length + 5; i++) { sheet1.getRow(i).getCell(0).setCellValue(ElementUtils.skf[i - 5]); sheet1.getRow(i).getCell(0).setCellStyle(csLeft); for (int j = 1; j <= array.size(); j++) { sheet1.getRow(i).getCell(j).setCellValue("0.0"); sheet1.getRow(i).getCell(j).setCellStyle(csRight); } } // Copies values in SampleLibrary array into report for (int i = 0; i < array.size(); i++) { List<Element> eleArray = array.get(i).getArrayCopy(); for (int j = 0; j < ElementUtils.skf.length; j++) { for (int k = 0; k < eleArray.size(); k++) { if (ElementUtils.skf[j].contains(eleArray.get(k).getBaseElement())) sheet1.getRow(j + 5).getCell(i + 1).setCellValue(eleArray.get(k).getConcWeight()); } } } try { wb.write(fileOut); wb.close(); fileOut.close(); } catch (IOException ex) { Logger.getLogger(SampleLibrary.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:eu.alpinweiss.filegen.service.impl.GenerateXlsxFileServiceImpl.java
License:Apache License
public void generateExcel(String excelFilename, int rowCount, List<FieldDefinition> fieldDefinitionList, int sheetCount) { long startTime = new Date().getTime(); outputWriterHolder.writeValueInLine("Excel data generation started"); Workbook wb = new SXSSFWorkbook(); try {//from w w w. j ava 2 s.c o m CellStyle cs = wb.createCellStyle(); cs.setFillForegroundColor(IndexedColors.LIME.getIndex()); cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); Font f = wb.createFont(); f.setBoldweight(Font.BOLDWEIGHT_BOLD); f.setFontHeightInPoints((short) 12); cs.setFont(f); SXSSFSheet sheet1 = (SXSSFSheet) wb.createSheet("dataSheet"); int columnCount = fieldDefinitionList.size(); Map<Integer, Input2TableInfo> input2TableInfoMap = new LinkedHashMap<>(columnCount); for (int i = 0; i < columnCount; i++) { Input2TableInfo input2TableInfo = new Input2TableInfo(); FieldDefinition fieldDefinition = fieldDefinitionList.get(i); input2TableInfo.setFieldText(fieldDefinition.getFieldName()); input2TableInfo.setFieldDefinition(fieldDefinition); input2TableInfo.initCellStyle(wb); input2TableInfo.initGenerator(); input2TableInfoMap.put(i, input2TableInfo); } if (sheetCount > 1) { CountDownLatch startSignal = new CountDownLatch(1); CountDownLatch doneSignal; doneSignal = new CountDownLatch(sheetCount); ParameterVault parameterVault = new DefaultParameterVault(0, rowCount); SheetProcessor stringProcessorSheet1 = new SheetProcessor(parameterVault, startSignal, doneSignal, cs, sheet1, columnCount, input2TableInfoMap, outputWriterHolder); new Thread(stringProcessorSheet1, "Processor-" + sheetCount).start(); for (int i = 0; i < sheetCount - 1; i++) { SXSSFSheet sheet = (SXSSFSheet) wb.createSheet("dataSheet_" + i); ParameterVault parameterVaultRest = new DefaultParameterVault(i + 1, rowCount); SheetProcessor stringProcessor = new SheetProcessor(parameterVaultRest, startSignal, doneSignal, cs, sheet, columnCount, input2TableInfoMap, outputWriterHolder); new Thread(stringProcessor, "Processor-" + i).start(); } startSignal.countDown(); doneSignal.await(); } else { ParameterVault parameterVault = new DefaultParameterVault(0, rowCount); new SheetProcessor(outputWriterHolder).generateSheetData(parameterVault, cs, sheet1, columnCount, input2TableInfoMap); } outputWriterHolder.writeValueInLine("Excel data generation finished."); long generationTime = new Date().getTime(); outputWriterHolder.writeValueInLine("Time used " + ((generationTime - startTime) / 1000) + " sec"); outputWriterHolder.writeValueInLine("Writing to file."); FileOutputStream fileOut = new FileOutputStream(excelFilename.trim()); wb.write(fileOut); fileOut.close(); long writeTime = new Date().getTime(); outputWriterHolder.writeValueInLine("Time used " + ((writeTime - generationTime) / 1000) + " sec"); outputWriterHolder.writeValueInLine("Total time used " + ((writeTime - startTime) / 1000) + " sec"); outputWriterHolder.writeValueInLine("Done"); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } finally { try { wb.close(); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } }
From source file:Excel.Exportar.java
public String exportarExcel() { String respuesta = "No se pudo exportar"; Workbook libro = new HSSFWorkbook(); Sheet hoja = libro.createSheet("Resultados"); String file = "Resultado.xls"; try {//from w w w.j a v a2 s .c o m for (int i = -1; i < 10; i++) { Row fila = hoja.createRow(i + 1); for (int j = 0; j < 2; j++) { Cell celda = fila.createCell(j); if (i == -1) { celda.setCellValue(encabezados[j]); } else { if (j == 0) { celda.setCellValue(cromosomas[i]); } else { celda.setCellValue(cromosomasMutados[i]); } } libro.write(new FileOutputStream(file)); } } respuesta = "Exportacion exitosa"; } catch (Exception e) { System.err.print(e); } return respuesta; }
From source file:Excel.ParticipantesProyectoExcel.java
@Override protected void buildExcelDocument(Map<String, Object> map, Workbook wrkbk, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { hsr1.setHeader("Content-Disposition", "attachment; filename=\"ParticipantesProyecto.xls\""); List<Participante> participantes = (List) map.get("listaParticipantes"); PruebaProyectoDAO proyecto_bd = (PruebaProyectoDAO) map.get("proyectobd"); Sheet sheet = wrkbk.createSheet("Participantes_informacion"); Row header = sheet.createRow(0);//from w ww . j ava2 s. c o m header.createCell(0).setCellValue("Nombre"); header.createCell(1).setCellValue("Apellido paterno"); header.createCell(2).setCellValue("Apellido materno"); header.createCell(3).setCellValue("Telefono"); header.createCell(4).setCellValue("Celular"); header.createCell(5).setCellValue("Correo"); header.createCell(6).setCellValue("Puesto"); int contador = 1; for (Participante participante : participantes) { Row courseRow = sheet.createRow(contador); courseRow.createCell(0).setCellValue(participante.getPersona().getNombre()); courseRow.createCell(1).setCellValue(participante.getPersona().getApp()); courseRow.createCell(2).setCellValue(participante.getPersona().getApm()); courseRow.createCell(3).setCellValue(participante.getPersona().getTelefono()); courseRow.createCell(4).setCellValue(participante.getPersona().getCelular()); courseRow.createCell(5).setCellValue(participante.getPersona().getCorreo()); courseRow.createCell(6).setCellValue(participante.getPuestoParticipante()); contador++; } // Hace que el ancho de la comlumna sea lo suficientemente grande // para que la informacin sea desplegada adecuadamente. sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); sheet.autoSizeColumn(4); sheet.autoSizeColumn(5); sheet.autoSizeColumn(6); RespuestaDAO respuesta_bd = (RespuestaDAO) map.get("respuestabd"); long idProyecto = (long) map.get("idproyecto"); List<PruebaProyecto> lp = proyecto_bd.getPruebasProyecto(idProyecto); boolean adaptabilidad = false; boolean clima = false; for (PruebaProyecto p : lp) { if (p.getPrueba() == 1) adaptabilidad = true; if (p.getPrueba() == 2) clima = true; } if (adaptabilidad) { Sheet sheet2 = wrkbk.createSheet("Respuestas_Adaptabilidad"); Row header2 = sheet2.createRow(0); header2.createCell(0).setCellValue("Nombre"); header2.createCell(1).setCellValue("Apellido paterno"); header2.createCell(2).setCellValue("Apellido materno"); header2.createCell(3).setCellValue("respuesta 1"); header2.createCell(4).setCellValue("respuesta 2"); header2.createCell(5).setCellValue("respuesta 3"); header2.createCell(6).setCellValue("respuesta 4"); header2.createCell(7).setCellValue("respuesta 5"); header2.createCell(8).setCellValue("respuesta 6"); header2.createCell(9).setCellValue("respuesta 7"); header2.createCell(10).setCellValue("respuesta 8"); header2.createCell(11).setCellValue("respuesta 9"); header2.createCell(12).setCellValue("respuesta 10"); header2.createCell(13).setCellValue("respuesta 11"); header2.createCell(14).setCellValue("respuesta 12"); header2.createCell(15).setCellValue("respuesta 13"); header2.createCell(16).setCellValue("respuesta 14"); header2.createCell(17).setCellValue("respuesta 15"); header2.createCell(18).setCellValue("respuesta 16"); header2.createCell(19).setCellValue("respuesta 17"); header2.createCell(20).setCellValue("respuesta 18"); header2.createCell(21).setCellValue("respuesta 19"); header2.createCell(22).setCellValue("respuesta 20"); header2.createCell(23).setCellValue("respuesta 21"); header2.createCell(24).setCellValue("respuesta 22"); header2.createCell(25).setCellValue("respuesta 23"); header2.createCell(26).setCellValue("respuesta 24"); header2.createCell(27).setCellValue("respuesta 25"); header2.createCell(28).setCellValue("respuesta 26"); header2.createCell(29).setCellValue("respuesta 27"); header2.createCell(30).setCellValue("respuesta 28"); header2.createCell(31).setCellValue("respuesta 29"); header2.createCell(32).setCellValue("respuesta 30"); header2.createCell(33).setCellValue("fecha"); header2.createCell(34).setCellValue("Eficacia"); header2.createCell(35).setCellValue("Creatividad"); header2.createCell(36).setCellValue("Relaciones Interpersonales"); header2.createCell(37).setCellValue("Adaptabilidad total"); contador = 1; for (Participante participante : participantes) { Row courseRow = sheet2.createRow(contador); courseRow.createCell(0).setCellValue(participante.getPersona().getNombre()); courseRow.createCell(1).setCellValue(participante.getPersona().getApp()); courseRow.createCell(2).setCellValue(participante.getPersona().getApm()); RAdaptabilidad ra = respuesta_bd.rAdaptabilidadCandidato(participante.getPersona().getIdPersona()); if (ra != null) { System.out.println("si respondio"); courseRow.createCell(3).setCellValue(ra.getRespuesta1()); courseRow.createCell(4).setCellValue(ra.getRespuesta2()); courseRow.createCell(5).setCellValue(ra.getRespuesta3()); courseRow.createCell(6).setCellValue(ra.getRespuesta4()); courseRow.createCell(7).setCellValue(ra.getRespuesta5()); courseRow.createCell(8).setCellValue(ra.getRespuesta6()); courseRow.createCell(9).setCellValue(ra.getRespuesta7()); courseRow.createCell(10).setCellValue(ra.getRespuesta8()); courseRow.createCell(11).setCellValue(ra.getRespuesta9()); courseRow.createCell(12).setCellValue(ra.getRespuesta10()); courseRow.createCell(13).setCellValue(ra.getRespuesta11()); courseRow.createCell(14).setCellValue(ra.getRespuesta12()); courseRow.createCell(15).setCellValue(ra.getRespuesta13()); courseRow.createCell(16).setCellValue(ra.getRespuesta14()); courseRow.createCell(17).setCellValue(ra.getRespuesta15()); courseRow.createCell(18).setCellValue(ra.getRespuesta16()); courseRow.createCell(19).setCellValue(ra.getRespuesta17()); courseRow.createCell(20).setCellValue(ra.getRespuesta18()); courseRow.createCell(21).setCellValue(ra.getRespuesta19()); courseRow.createCell(22).setCellValue(ra.getRespuesta20()); courseRow.createCell(23).setCellValue(ra.getRespuesta21()); courseRow.createCell(24).setCellValue(ra.getRespuesta22()); courseRow.createCell(25).setCellValue(ra.getRespuesta23()); courseRow.createCell(26).setCellValue(ra.getRespuesta24()); courseRow.createCell(27).setCellValue(ra.getRespuesta25()); courseRow.createCell(28).setCellValue(ra.getRespuesta26()); courseRow.createCell(29).setCellValue(ra.getRespuesta27()); courseRow.createCell(30).setCellValue(ra.getRespuesta28()); courseRow.createCell(31).setCellValue(ra.getRespuesta29()); courseRow.createCell(32).setCellValue(ra.getRespuesta30()); courseRow.createCell(33).setCellValue(ra.getFechaRespuesta().toString()); int ef = ra.getRespuesta1() + ra.getRespuesta2() + ra.getRespuesta3() + ra.getRespuesta4() + ra.getRespuesta5() + ra.getRespuesta6() + ra.getRespuesta7() + ra.getRespuesta8() + ra.getRespuesta9() + ra.getRespuesta10(); int cr = ra.getRespuesta11() + ra.getRespuesta12() + ra.getRespuesta13() + ra.getRespuesta14() + ra.getRespuesta15() + ra.getRespuesta17() + ra.getRespuesta18() + ra.getRespuesta19() + ra.getRespuesta20(); int ri = ra.getRespuesta21() + ra.getRespuesta22() + ra.getRespuesta23() + ra.getRespuesta24() + ra.getRespuesta25() + ra.getRespuesta26() + ra.getRespuesta27() + ra.getRespuesta28() + ra.getRespuesta29() + ra.getRespuesta30(); int ta = ef + cr + ri; courseRow.createCell(34).setCellValue(ef); courseRow.createCell(35).setCellValue(cr); courseRow.createCell(36).setCellValue(ri); courseRow.createCell(37).setCellValue(ri); } contador++; } // Hace que el ancho de la comlumna sea lo suficientemente grande // para que la informacin sea desplegada adecuadamente. sheet2.autoSizeColumn(0); sheet2.autoSizeColumn(1); sheet2.autoSizeColumn(2); sheet2.autoSizeColumn(3); sheet2.autoSizeColumn(4); sheet2.autoSizeColumn(5); sheet2.autoSizeColumn(6); sheet2.autoSizeColumn(7); sheet2.autoSizeColumn(8); sheet2.autoSizeColumn(9); sheet2.autoSizeColumn(10); sheet2.autoSizeColumn(11); sheet2.autoSizeColumn(12); sheet2.autoSizeColumn(13); sheet2.autoSizeColumn(14); sheet2.autoSizeColumn(15); sheet2.autoSizeColumn(16); sheet2.autoSizeColumn(17); sheet2.autoSizeColumn(18); sheet2.autoSizeColumn(19); sheet2.autoSizeColumn(20); sheet2.autoSizeColumn(21); sheet2.autoSizeColumn(22); sheet2.autoSizeColumn(23); sheet2.autoSizeColumn(24); sheet2.autoSizeColumn(25); sheet2.autoSizeColumn(26); sheet2.autoSizeColumn(27); sheet2.autoSizeColumn(28); sheet2.autoSizeColumn(29); sheet2.autoSizeColumn(30); sheet2.autoSizeColumn(31); sheet2.autoSizeColumn(32); sheet2.autoSizeColumn(33); sheet2.autoSizeColumn(34); sheet2.autoSizeColumn(35); sheet2.autoSizeColumn(36); sheet2.autoSizeColumn(37); } if (clima) { Sheet sheet3 = wrkbk.createSheet("Respuestas_Clima"); Row header3 = sheet3.createRow(0); header3.createCell(0).setCellValue("Nombre"); header3.createCell(1).setCellValue("Apellido paterno"); header3.createCell(2).setCellValue("Apellido materno"); header3.createCell(3).setCellValue("respuesta 1"); header3.createCell(4).setCellValue("respuesta 2"); header3.createCell(5).setCellValue("respuesta 3"); header3.createCell(6).setCellValue("respuesta 4"); header3.createCell(7).setCellValue("respuesta 5"); header3.createCell(8).setCellValue("respuesta 6"); header3.createCell(9).setCellValue("respuesta 7"); header3.createCell(10).setCellValue("respuesta 8"); header3.createCell(11).setCellValue("respuesta 9"); header3.createCell(12).setCellValue("respuesta 10"); header3.createCell(13).setCellValue("respuesta 11"); header3.createCell(14).setCellValue("respuesta 12"); header3.createCell(15).setCellValue("respuesta 13"); header3.createCell(16).setCellValue("respuesta 14"); header3.createCell(17).setCellValue("respuesta 15"); header3.createCell(18).setCellValue("respuesta 16"); header3.createCell(19).setCellValue("respuesta 17"); header3.createCell(20).setCellValue("respuesta 18"); header3.createCell(21).setCellValue("respuesta 19"); header3.createCell(22).setCellValue("respuesta 20"); header3.createCell(23).setCellValue("fecha"); header3.createCell(24).setCellValue("Interaccin con las Autoridades"); header3.createCell(25).setCellValue("Carga de Trabajo"); header3.createCell(26).setCellValue("Ambiente Fsico"); header3.createCell(27).setCellValue("Total"); contador = 1; for (Participante participante : participantes) { Row courseRow = sheet3.createRow(contador); courseRow.createCell(0).setCellValue(participante.getPersona().getNombre()); courseRow.createCell(1).setCellValue(participante.getPersona().getApp()); courseRow.createCell(2).setCellValue(participante.getPersona().getApm()); RClimaLaboral ra = respuesta_bd.rClimaCandidato(participante.getPersona().getIdPersona()); if (ra != null) { courseRow.createCell(3).setCellValue(ra.getRespuesta1()); courseRow.createCell(4).setCellValue(ra.getRespuesta2()); courseRow.createCell(5).setCellValue(ra.getRespuesta3()); courseRow.createCell(6).setCellValue(ra.getRespuesta4()); courseRow.createCell(7).setCellValue(ra.getRespuesta5()); courseRow.createCell(8).setCellValue(ra.getRespuesta6()); courseRow.createCell(9).setCellValue(ra.getRespuesta7()); courseRow.createCell(10).setCellValue(ra.getRespuesta8()); courseRow.createCell(11).setCellValue(ra.getRespuesta9()); courseRow.createCell(12).setCellValue(ra.getRespuesta10()); courseRow.createCell(13).setCellValue(ra.getRespuesta11()); courseRow.createCell(14).setCellValue(ra.getRespuesta12()); courseRow.createCell(15).setCellValue(ra.getRespuesta13()); courseRow.createCell(16).setCellValue(ra.getRespuesta14()); courseRow.createCell(17).setCellValue(ra.getRespuesta15()); courseRow.createCell(18).setCellValue(ra.getRespuesta16()); courseRow.createCell(19).setCellValue(ra.getRespuesta17()); courseRow.createCell(20).setCellValue(ra.getRespuesta18()); courseRow.createCell(21).setCellValue(ra.getRespuesta19()); courseRow.createCell(22).setCellValue(ra.getRespuesta20()); courseRow.createCell(23).setCellValue(ra.getFechaRespuesta().toString()); int ia = ra.getRespuesta3() + ra.getRespuesta8() + ra.getRespuesta10() + ra.getRespuesta15() + ra.getRespuesta16() + ra.getRespuesta16(); int ct = ra.getRespuesta5() + ra.getRespuesta7() + ra.getRespuesta18() + ra.getRespuesta20(); int af = ra.getRespuesta1() + ra.getRespuesta2() + ra.getRespuesta4() + ra.getRespuesta4() + ra.getRespuesta6() + ra.getRespuesta9() + ra.getRespuesta11() + ra.getRespuesta12() + ra.getRespuesta13() + ra.getRespuesta14() + ra.getRespuesta19(); int tc = ia + ct + af; courseRow.createCell(24).setCellValue(ia); courseRow.createCell(25).setCellValue(ct); courseRow.createCell(26).setCellValue(af); courseRow.createCell(27).setCellValue(tc); } contador++; } // Hace que el ancho de la comlumna sea lo suficientemente grande // para que la informacin sea desplegada adecuadamente. sheet3.autoSizeColumn(0); sheet3.autoSizeColumn(1); sheet3.autoSizeColumn(2); sheet3.autoSizeColumn(3); sheet3.autoSizeColumn(4); sheet3.autoSizeColumn(5); sheet3.autoSizeColumn(6); sheet3.autoSizeColumn(7); sheet3.autoSizeColumn(8); sheet3.autoSizeColumn(9); sheet3.autoSizeColumn(10); sheet3.autoSizeColumn(11); sheet3.autoSizeColumn(12); sheet3.autoSizeColumn(13); sheet3.autoSizeColumn(14); sheet3.autoSizeColumn(15); sheet3.autoSizeColumn(16); sheet3.autoSizeColumn(17); sheet3.autoSizeColumn(18); sheet3.autoSizeColumn(19); sheet3.autoSizeColumn(20); sheet3.autoSizeColumn(21); sheet3.autoSizeColumn(22); sheet3.autoSizeColumn(23); sheet3.autoSizeColumn(24); sheet3.autoSizeColumn(25); sheet3.autoSizeColumn(26); sheet3.autoSizeColumn(27); } }
From source file:ExcelView.ClientesExcelView.java
@Override protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setHeader("Content-Disposition", "attachment; filename=\"datos Clientes.xls\""); Sheet sheet = workbook.createSheet("Datos_Clientes"); List<Cliente> clientes = (List) model.get("clientes"); Row header = sheet.createRow(0);//from w w w. ja va 2 s. co m header.createCell(0).setCellValue("Correo"); header.createCell(1).setCellValue("Nombre"); header.createCell(2).setCellValue("Apellido Paterno"); header.createCell(3).setCellValue("Apellido Materno"); header.createCell(4).setCellValue("Telefono Local"); header.createCell(5).setCellValue("Telefono Movil"); header.createCell(6).setCellValue("Area"); header.createCell(7).setCellValue("Puesto"); header.createCell(8).setCellValue("Nombre Empresa"); int contador = 1; for (Cliente cliente : clientes) { Row courseRow = sheet.createRow(contador); courseRow.createCell(0).setCellValue(cliente.getCorreo()); courseRow.createCell(1).setCellValue(cliente.getNombre_cliente()); courseRow.createCell(2).setCellValue(cliente.getApellido_paterno_cliente()); courseRow.createCell(3).setCellValue(cliente.getApellido_materno_cliente()); courseRow.createCell(4).setCellValue(cliente.getTelefono_local()); courseRow.createCell(5).setCellValue(cliente.getTelefono_movil()); courseRow.createCell(6).setCellValue(cliente.getArea()); courseRow.createCell(7).setCellValue(cliente.getPuesto()); courseRow.createCell(8).setCellValue(cliente.getNombre_empresa()); contador++; } // Hace que el ancho de la comlumna sea lo suficientemente grande // para que la informacin sea desplegada adecuadamente. sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); sheet.autoSizeColumn(3); sheet.autoSizeColumn(4); sheet.autoSizeColumn(5); sheet.autoSizeColumn(6); sheet.autoSizeColumn(7); sheet.autoSizeColumn(8); }
From source file:Export.ExporOnlyViagemExcel.java
private void dataTableDados(Workbook wb, Date dataInicio, Date dataFim) throws ParseException { Font fTitulo = wb.createFont(); fTitulo.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTitulo.setFontHeightInPoints((short) 14); Font fTituloP = wb.createFont(); fTituloP.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTituloP.setFontHeightInPoints((short) 12); // fTituloP.setStrikeout(true); fTituloP.setUnderline(org.apache.poi.ss.usermodel.Font.U_SINGLE); Font fTituloTabela = wb.createFont(); fTituloTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fTituloTabela.setFontHeightInPoints((short) 8); Font fCorpoTabela = wb.createFont(); fCorpoTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_NORMAL); fCorpoTabela.setFontHeightInPoints((short) 8.5); Font fRodapeTabela = wb.createFont(); fRodapeTabela.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fRodapeTabela.setFontHeightInPoints((short) 8.5); Font fNormal = wb.createFont(); fNormal.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); fNormal.setFontHeightInPoints((short) 8.5); CellStyle csTitulo = wb.createCellStyle(); csTitulo.setFont(fTitulo);/*from w w w . j a v a 2 s .com*/ csTitulo.setAlignment((short) 1); csTitulo.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM); csTitulo.setBorderBottom((short) 0); csTitulo.setBorderTop((short) 0); csTitulo.setBorderRight((short) 0); csTitulo.setBorderLeft((short) 0); csTitulo.setWrapText(true); CellStyle csTituloP = wb.createCellStyle(); csTituloP.setFont(fTituloP); csTituloP.setAlignment((short) 1); csTituloP.setVerticalAlignment((short) 1); csTituloP.setBorderBottom((short) 0); csTituloP.setBorderTop((short) 0); csTituloP.setBorderRight((short) 0); csTituloP.setBorderLeft((short) 0); csTituloP.setWrapText(true); CellStyle csTituloT = wb.createCellStyle(); csTituloT.setFont(fTituloP); csTituloT.setAlignment((short) 1); csTituloT.setVerticalAlignment((short) 1); csTituloT.setBorderBottom((short) 0); csTituloT.setBorderTop((short) 0); csTituloT.setBorderRight((short) 0); csTituloT.setBorderLeft((short) 0); csTituloT.setWrapText(true); CellStyle csTituloTabela = wb.createCellStyle(); csTituloTabela.setFont(fTituloTabela); csTituloTabela.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabela.setVerticalAlignment((short) 2); csTituloTabela.setBorderBottom((short) 2); csTituloTabela.setBorderTop((short) 2); csTituloTabela.setBorderRight((short) 2); csTituloTabela.setBorderLeft((short) 2); csTituloTabela.setWrapText(true); CellStyle csTituloTabelaNBorder = wb.createCellStyle(); csTituloTabelaNBorder.setFont(fTituloTabela); csTituloTabelaNBorder.setAlignment(CellStyle.ALIGN_CENTER); csTituloTabelaNBorder.setVerticalAlignment((short) 2); csTituloTabelaNBorder.setBorderBottom((short) 2); csTituloTabelaNBorder.setBorderTop((short) 2); csTituloTabelaNBorder.setBorderRight((short) 2); csTituloTabelaNBorder.setBorderLeft((short) 2); csTituloTabelaNBorder.setWrapText(true); CellStyle csCorpoTabela = wb.createCellStyle(); csCorpoTabela.setFont(fCorpoTabela); csCorpoTabela.setAlignment((short) 2); csCorpoTabela.setVerticalAlignment((short) 1); csCorpoTabela.setBorderBottom((short) 1); csCorpoTabela.setBorderTop((short) 1); csCorpoTabela.setBorderRight((short) 1); csCorpoTabela.setBorderLeft((short) 1); csCorpoTabela.setWrapText(true); CellStyle csCorpoTabelaR = wb.createCellStyle(); csCorpoTabelaR.setFont(fCorpoTabela); csCorpoTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csCorpoTabelaR.setVerticalAlignment((short) 1); csCorpoTabelaR.setBorderBottom((short) 1); csCorpoTabelaR.setBorderTop((short) 1); csCorpoTabelaR.setBorderRight((short) 1); csCorpoTabelaR.setBorderLeft((short) 1); csCorpoTabelaR.setWrapText(true); CellStyle csCorpoTabelaL = wb.createCellStyle(); csCorpoTabelaL.setFont(fCorpoTabela); csCorpoTabelaL.setAlignment(CellStyle.ALIGN_LEFT); csCorpoTabelaL.setVerticalAlignment((short) 1); csCorpoTabelaL.setBorderBottom((short) 1); csCorpoTabelaL.setBorderTop((short) 1); csCorpoTabelaL.setBorderRight((short) 1); csCorpoTabelaL.setBorderLeft((short) 1); csCorpoTabelaL.setWrapText(true); CellStyle csRodapeTabela = wb.createCellStyle(); csRodapeTabela.setFont(fRodapeTabela); csRodapeTabela.setAlignment((short) 1); csRodapeTabela.setVerticalAlignment((short) 2); csRodapeTabela.setBorderBottom((short) 2); csRodapeTabela.setBorderTop((short) 2); csRodapeTabela.setBorderRight((short) 2); csRodapeTabela.setBorderLeft((short) 2); csRodapeTabela.setWrapText(true); CellStyle csRodapeTabelaR = wb.createCellStyle(); csRodapeTabelaR.setFont(fRodapeTabela); csRodapeTabelaR.setAlignment(CellStyle.ALIGN_RIGHT); csRodapeTabelaR.setVerticalAlignment((short) 2); csRodapeTabelaR.setBorderBottom((short) 2); csRodapeTabelaR.setBorderTop((short) 2); csRodapeTabelaR.setBorderRight((short) 2); csRodapeTabelaR.setBorderLeft((short) 2); csRodapeTabelaR.setWrapText(true); CellStyle csNomal = wb.createCellStyle(); csNomal.setFont(fCorpoTabela); csNomal.setAlignment((short) 1); csNomal.setVerticalAlignment((short) 1); csNomal.setBorderBottom((short) 0); csNomal.setBorderTop((short) 0); csNomal.setBorderRight((short) 0); csNomal.setBorderLeft((short) 0); csNomal.setWrapText(true); int i, p = 0; dataViagem(dataInicio, dataFim); for (Map.Entry<String, ArrayList<HashMap<String, Object>>> data : hasList.entrySet()) { totalSelo = 0f; totalConsumo = 0f; totalTotal = 0f; totalPremio = 0f; totalComissao = 0f; linha = 0; SimpleDateFormat sdfEsp = new SimpleDateFormat("MMMM, yyyy", Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy"); String titile = sdfEsp.format(sdf.parse((data.getKey()))).toUpperCase(); Sheet s = wb.createSheet(titile); dataTableTitile(s, titile, csTitulo, csTituloP, csTituloTabelaNBorder); Row r = s.createRow(linha); Cell c = r.createCell(2); for (int j = 0; j < 13; j++) { switch (j) { case 0: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 1, 4); break; case 1: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 2, 6); break; case 2: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 3, 8); break; case 3: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 4, 6); break; case 4: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 5, 6); break; case 5: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 6, 4); break; case 6: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 7, 25); break; case 7: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 8, 10); break; case 8: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 9, 10); break; case 9: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 10, 8); break; case 10: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 11, 8); break; case 11: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 12, 8); break; case 12: createCell(c, r, s, csTituloTabela, linha, linha, funcaoTitulo(j), 13, 8); break; default: break; } } i = 1; for (HashMap<String, Object> hashMap : data.getValue()) { linha++; r = s.createRow(linha); c = r.createCell(2); createCell(c, r, s, csCorpoTabela, linha, linha, (i + ""), 1, 4); createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(DATA)), 2, 6); createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(NUMEROAPOLICE)), 3, 7); createCell(c, r, s, csCorpoTabela, linha, linha, ConfigDoc.toFormat(toString(hashMap.get(INICIO)), "dd-MM-yyyy", "yyyy-MM-dd"), 4, 6); createCell(c, r, s, csCorpoTabela, linha, linha, ConfigDoc.toFormat(toString(hashMap.get(FIM)), "dd-MM-yyyy", "yyyy-MM-dd"), 5, 6); createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(DIAS)), 6, 4); createCell(c, r, s, csCorpoTabelaL, linha, linha, toString(hashMap.get(CLIENTE)), 7, 20); createCell(c, r, s, csCorpoTabela, linha, linha, toString(hashMap.get(RECIBO)), 8, 10); createCell(c, r, s, csCorpoTabelaR, linha, linha, toString(hashMap.get(PREMIO)), 9, 10); totalComissao += toFloat(toString(hashMap.get(COMISSAO))); createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toString(hashMap.get(COMISSAO)), ""), 10, 8); totalConsumo += toFloat(toString(hashMap.get(CONSUMO))); createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toString(hashMap.get(CONSUMO)), ""), 11, 8); totalSelo += toFloat(toString(hashMap.get(SELO))); createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toString(hashMap.get(SELO)), ""), 12, 8); totalTotal += toFloat(toString(hashMap.get(TOTAL))); createCell(c, r, s, csCorpoTabelaR, linha, linha, ConfigDoc.toMoeda(toString(hashMap.get(TOTAL)), ""), 13, 8); i++; } linha++; radapeTable(s, csRodapeTabelaR); } }