List of usage examples for org.apache.poi.ss.usermodel CellStyle setFillPattern
void setFillPattern(FillPatternType fp);
From source file:com.wantdo.stat.excel.poi_src.SSPerformanceTest.java
License:Apache License
static Map<String, CellStyle> createStyles(Workbook wb) { Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); CellStyle style; Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 14); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle();/*from w w w. j a v a2 s . co m*/ style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFont(headerFont); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); styles.put("header", style); Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short) 12); monthFont.setColor(IndexedColors.RED.getIndex()); monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(monthFont); styles.put("red-bold", style); String[] nfmt = { "#,##0.00", "$#,##0.00", "m/d/yyyy" }; for (String fmt : nfmt) { style = wb.createCellStyle(); style.setDataFormat(wb.createDataFormat().getFormat(fmt)); styles.put(fmt, style); } return styles; }
From source file:com.ykun.commons.utils.excel.ExcelUtils.java
License:Apache License
/** * ??/*from w ww .ja v a2 s.c o m*/ * * @param workbook Workbook * @return CellStyle */ private static CellStyle createHeaderStyle(Workbook workbook) { CellStyle style = workbook.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = workbook.createFont(); headerFont.setBold(Boolean.TRUE); headerFont.setColor(IndexedColors.BLACK.getIndex()); style.setFont(headerFont); return style; }
From source file:com.zlfun.framework.excel.ExcelUtils.java
public static CellStyle createHeaderStyle(Workbook workbook) { CellStyle style = workbook.createCellStyle(); // ?/*w w w.ja v a 2 s . c o m*/ style.setFillForegroundColor(HSSFColor.SKY_BLUE.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setAlignment(CellStyle.ALIGN_CENTER); // ? Font font = workbook.createFont(); font.setColor(HSSFColor.VIOLET.index); font.setFontHeightInPoints((short) 12); font.setBoldweight(Font.BOLDWEIGHT_BOLD); // ?? style.setFont(font); return style; }
From source file:com.zlfun.framework.excel.ExcelUtils.java
public static CellStyle createBodyStyle(Workbook workbook) { CellStyle style = workbook.createCellStyle(); // ?/* w w w. j a v a 2s . c om*/ style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); // ?? Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); // ?? style.setFont(font); return style; }
From source file:Compras.altaCompras.java
private void b_muestraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_muestraActionPerformed // TODO add your handling code here: javax.swing.JFileChooser jF1= new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null;//w w w . j av a 2 s. c om if(jF1.showSaveDialog(null)==jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); File archivoXLS = new File(ruta+".xls"); try { if(archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Muestras"); org.apache.poi.ss.usermodel.Font font10 = libro.createFont(); font10.setFontHeightInPoints((short)10); font10.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font10.setColor(new HSSFColor.YELLOW().getIndex()); CellStyle titulo = libro.createCellStyle(); CellStyle contenido = libro.createCellStyle(); CellStyle firma = libro.createCellStyle(); CellStyle costado = libro.createCellStyle(); CellStyle derecha = libro.createCellStyle(); CellStyle derecha_borde = libro.createCellStyle(); titulo.setFont(font10); titulo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); titulo.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); titulo.setAlignment(CellStyle.ALIGN_CENTER); contenido.setBorderBottom(HSSFCellStyle.BORDER_THIN); contenido.setBorderTop(HSSFCellStyle.BORDER_THIN); contenido.setBorderRight(HSSFCellStyle.BORDER_THIN); contenido.setBorderLeft(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderBottom(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderTop(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderRight(HSSFCellStyle.BORDER_THIN); derecha_borde.setBorderLeft(HSSFCellStyle.BORDER_THIN); derecha_borde.setAlignment(CellStyle.ALIGN_RIGHT); derecha.setAlignment(CellStyle.ALIGN_RIGHT); firma.setBorderTop(HSSFCellStyle.BORDER_THIN); firma.setAlignment(CellStyle.ALIGN_CENTER); //costado.setBorderLeft(HSSFCellStyle.BORDER_THIN); hoja.setColumnWidth(0, 3000); hoja.setColumnWidth(2, 3000); hoja.setColumnWidth(3, 8000); hoja.setColumnWidth(4, 5000); try { InputStream is = new FileInputStream("imagenes/grande300115.jpg"); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = libro.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); is.close(); CreationHelper helper = libro.getCreationHelper(); Drawing drawing = hoja.createDrawingPatriarch(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setCol1(0); anchor.setRow1(0); Picture pict = drawing.createPicture(anchor, pictureIdx); pict.resize(); }catch(Exception e){e.printStackTrace();} Row r7 = hoja.createRow(7); r7.createCell(0).setCellValue("ORDEN:"); r7.createCell(1).setCellValue(String.valueOf(ord.getIdOrden())); r7.createCell(2).setCellValue("Hrs. Entrega:"); r7.createCell(3).setCellValue(""); hoja.addMergedRegion(new CellRangeAddress(7,7,4,7)); r7.createCell(4).setCellValue("ORDEN PARA SURTIR MUESTRAS"); r7.getCell(4).setCellStyle(derecha); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS String valor=dateFormat.format(fecha); Row r8 = hoja.createRow(8); r8.createCell(0).setCellValue("Supervisor:"); hoja.addMergedRegion(new CellRangeAddress(8,8,1,3)); r8.createCell(1).setCellValue(""); r8.createCell(4).setCellValue("F. Elaboracin:"); r8.createCell(5).setCellValue(valor); Row r9 = hoja.createRow(9); r9.createCell(0).setCellValue("Comprador:"); hoja.addMergedRegion(new CellRangeAddress(9,9,1,3)); r9.createCell(1).setCellValue(""); r9.createCell(4).setCellValue("F. Entrega:"); r9.createCell(5).setCellValue(""); Row r10 = hoja.createRow(10); r10.createCell(0).setCellValue("Cantidad"); r10.getCell(0).setCellStyle(titulo); hoja.addMergedRegion(new CellRangeAddress(10,10,1,7)); r10.createCell(1).setCellValue("Descripcin"); r10.getCell(1).setCellStyle(titulo); int ren=11; for(int r=0;r<(t_datos.getRowCount());r++) { if((boolean)t_titulos.getValueAt(r, 3)==true) { Row fila = hoja.createRow(ren); Cell celda = fila.createCell(0); celda.setCellStyle(derecha_borde); Cell celda1 = fila.createCell(1); celda1.setCellStyle(contenido); fila.createCell(2).setCellStyle(contenido); fila.createCell(3).setCellStyle(contenido); fila.createCell(4).setCellStyle(contenido); fila.createCell(5).setCellStyle(contenido); fila.createCell(6).setCellStyle(contenido); fila.createCell(7).setCellStyle(contenido); //Cell celda8 = fila.createCell(8); //celda8.setCellStyle(costado); try{ celda.setCellValue(t_datos.getValueAt(r, 14).toString()); hoja.addMergedRegion(new CellRangeAddress(ren,ren,1,7)); celda1.setCellValue(t_titulos.getValueAt(r, 2).toString()); //celda8.setCellValue(""); }catch(Exception e){ celda.setCellValue(""); } ren++; } } Row rx = hoja.createRow(ren+5); hoja.addMergedRegion(new CellRangeAddress(ren+5,ren+5,0,2)); rx.createCell(0).setCellValue("Recibe Muestras"); rx.getCell(0).setCellStyle(firma); rx.createCell(1).setCellStyle(firma); rx.createCell(2).setCellStyle(firma); hoja.addMergedRegion(new CellRangeAddress(ren+5,ren+5,5,7)); rx.createCell(5).setCellValue("Entrega Muestras"); rx.getCell(5).setCellStyle(firma); rx.createCell(6).setCellStyle(firma); rx.createCell(7).setCellStyle(firma); libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); }catch(Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } } }
From source file:Compras.generaCotizacion.java
void exel() { h = new Herramientas(this.user, 0); h.session(sessionPrograma);// w w w .j a va 2s . c o m javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { if (ruta.endsWith(".xls") == true) archivoXLS = new File(ruta); else archivoXLS = new File(ruta + ".xls"); try { if (archivoXLS.exists()) archivoXLS.delete(); archivoXLS.createNewFile(); Workbook libro = new HSSFWorkbook(); FileOutputStream archivo = new FileOutputStream(archivoXLS); Sheet hoja = libro.createSheet("Cotizacion"); Font font = libro.createFont(); font.setFontHeightInPoints((short) 24); font.setFontName("Arial"); font.setItalic(false); font.setBold(true); Font font10 = libro.createFont(); font10.setFontHeightInPoints((short) 10); font10.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font10.setColor(new HSSFColor.YELLOW().getIndex()); Font font11 = libro.createFont(); font11.setFontHeightInPoints((short) 10); font11.setFontName("Arial"); font10.setItalic(false); font10.setBold(false); font11.setColor(new HSSFColor.BLACK().getIndex()); // Fonts are set into a style so create a new one to use. CellStyle style = libro.createCellStyle(); CellStyle desBloqueo = libro.createCellStyle(); CellStyle desBloqueo1 = libro.createCellStyle(); CellStyle desBloqueoFecha = libro.createCellStyle(); style.setFont(font); desBloqueo.setFont(font10); desBloqueo.setLocked(false); desBloqueo.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); desBloqueo.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); desBloqueo1.setFont(font11); desBloqueo1.setLocked(false); desBloqueo1.setFillBackgroundColor(new HSSFColor.WHITE().getIndex()); desBloqueoFecha.setFont(font10); desBloqueoFecha.setLocked(false); desBloqueoFecha.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); desBloqueoFecha.setFillBackgroundColor(new HSSFColor.GREEN().getIndex()); desBloqueoFecha.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction().begin(); Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(orden)); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); hoja.setColumnWidth(5, 15000); Row r0 = hoja.createRow(0); Cell celdaTitulo = r0.createCell(0); celdaTitulo.setCellValue(con.getEmpresa()); celdaTitulo.setCellStyle(style); Row r1 = hoja.createRow(1); r1.createCell(6).setCellValue("Orden de Taller:"); r1.createCell(7).setCellValue(orden); Row r2 = hoja.createRow(2); r2.createCell(0).setCellValue("Marca:"); r2.createCell(1).setCellValue(ord.getMarca().getMarcaNombre()); r2.createCell(6).setCellValue("N Serie:"); r2.createCell(7).setCellValue(ord.getNoSerie()); Row r3 = hoja.createRow(3); r3.createCell(0).setCellValue("Tipo:"); r3.createCell(1).setCellValue(ord.getTipo().getTipoNombre()); r3.createCell(6).setCellValue("N Motor:"); r3.createCell(7).setCellValue(ord.getNoMotor()); Row r4 = hoja.createRow(4); r4.createCell(0).setCellValue("NP:"); r4.createCell(1).setCellValue(t_datos1.getValueAt(t_datos1.getSelectedRow(), 1).toString()); r4.createCell(2).setCellValue("Proveedor:"); r4.createCell(3).setCellValue(t_datos1.getValueAt(t_datos1.getSelectedRow(), 2).toString()); r4.createCell(6).setCellValue("Modelo:"); r4.createCell(7).setCellValue("" + ord.getModelo()); Row r5 = hoja.createRow(5); r5.createCell(0).setCellValue( "**********************************************************************************[Nota: Solo puedes editar las celdas de color]*******************************************************************************"); Row r6 = hoja.createRow(6); r6.createCell(0).setCellValue("Partida"); r6.createCell(1).setCellValue("sub"); r6.createCell(2).setCellValue("Cantidad"); r6.createCell(3).setCellValue("U/Medida"); r6.createCell(4).setCellValue("N Parte"); r6.createCell(5).setCellValue("Descripcion"); r6.createCell(6).setCellValue("Instruccin"); r6.createCell(7).setCellValue("Precio c/u"); r6.createCell(8).setCellValue("T o t a l"); r6.createCell(9).setCellValue("Origen"); r6.createCell(10).setCellValue("Pazo"); Row r7 = hoja.createRow(7); r7.createCell(0).setCellValue( "**********************************************************************************************************************************************************************************************************************"); List misCotizaciones = null; Query query = session.createQuery("SELECT DISTINCT par FROM Partida par " + "RIGHT JOIN FETCH par.partidaCotizacions partC " + "RIGHT JOIN partC.cotizacion cot " + "where cot.idCotizacion=" + t_datos1.getValueAt(t_datos1.getSelectedRow(), 0).toString() + " order by par.idEvaluacion asc, par.subPartida asc"); //misCotizaciones=c.addOrder(Order.asc("idCotizacion")).list(); misCotizaciones = query.list(); if (misCotizaciones.size() > 0) { for (int i = 0; i < misCotizaciones.size(); i++) { Partida Part = (Partida) misCotizaciones.get(i); Row fila = hoja.createRow(i + 8); fila.createCell(0).setCellValue(Part.getIdEvaluacion()); fila.createCell(1).setCellValue(Part.getSubPartida()); fila.createCell(2).setCellValue(Part.getCant()); fila.createCell(3).setCellValue(Part.getMed()); Cell aux = fila.createCell(4); aux.setCellStyle(desBloqueo); if (Part.getEjemplar() != null) aux.setCellValue(Part.getEjemplar().getIdParte()); else aux.setCellValue(""); fila.createCell(5).setCellValue(Part.getCatalogo().getNombre()); int fil = i + 9; Cell a10 = fila.createCell(6); a10.setCellStyle(desBloqueo1); a10.setCellValue(Part.getInstruccion()); Cell a6 = fila.createCell(7); a6.setCellStyle(desBloqueo); a6.setCellValue(""); Cell celForm = fila.createCell(8); celForm.setCellType(HSSFCell.CELL_TYPE_FORMULA); celForm.setCellFormula("H" + fil + "*C" + fil); if (Part.isOri() == true) fila.createCell(9).setCellValue("Ori"); else if (Part.isNal() == true) fila.createCell(9).setCellValue("Nal"); else if (Part.isDesm() == true) fila.createCell(9).setCellValue("Des"); else fila.createCell(9).setCellValue(""); Cell a9 = fila.createCell(10); a9.setCellValue(""); a9.setCellStyle(desBloqueo); } } hoja.protectSheet("04650077"); libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); if (session != null) if (session.isOpen()) session.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } } } }
From source file:controller.VisitasController.java
public void makeRowBold(Workbook wb, Row row) { CellStyle style = wb.createCellStyle();//Create style Font font = wb.createFont();//Create font font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(new HSSFColor.WHITE().getIndex());//Make font bold style.setFont(font);//set it to bold style.setAlignment(HorizontalAlignment.CENTER); style.setFillBackgroundColor(new HSSFColor.BLACK().getIndex()); style.setFillForegroundColor(new HSSFColor.BLACK().getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); for (int i = 0; i < row.getLastCellNum(); i++) { if (!row.getCell(i).getStringCellValue().equals("")) { row.getCell(i).setCellStyle(style);//Set the sty;e }// w ww . ja v a2s.c o m } }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetriever.java
License:Open Source License
/** * Creates an Excel worksheet containing the metric's data (timestamps and values) for the * specified time range. This worksheet is titled with the trhe metric's name and added to the * specified Workbook.//from ww w. j ava2s. c o m * * @param wb the workbook to add this worksheet to * @param metricName the name of the metric whose data is being rendered in this worksheet * @param rrdFilename the name of the RRD file to retrieve the metric's data from * @param startTime start time, in seconds since Unix epoch, to fetch metric's data * @param endTime end time, in seconds since Unix epoch, to fetch metric's data * @throws IOException * @throws MetricsGraphException */ private void createSheet(Workbook wb, String metricName, String rrdFilename, long startTime, long endTime) throws IOException, MetricsGraphException { LOGGER.trace("ENTERING: createSheet"); MetricData metricData = getMetricData(rrdFilename, startTime, endTime); String displayableMetricName = convertCamelCase(metricName); String title = displayableMetricName + " for " + getCalendarTime(startTime) + " to " + getCalendarTime(endTime); Sheet sheet = wb.createSheet(displayableMetricName); Font headerFont = wb.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle columnHeadingsStyle = wb.createCellStyle(); columnHeadingsStyle.setFont(headerFont); CellStyle bannerStyle = wb.createCellStyle(); bannerStyle.setFont(headerFont); bannerStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index); bannerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); int rowCount = 0; Row row = sheet.createRow((short) rowCount); Cell cell = row.createCell(0); cell.setCellValue(title); cell.setCellStyle(bannerStyle); rowCount++; // Blank row for spacing/readability row = sheet.createRow((short) rowCount); cell = row.createCell(0); cell.setCellValue(""); rowCount++; row = sheet.createRow((short) rowCount); cell = row.createCell(0); cell.setCellValue("Timestamp"); cell.setCellStyle(columnHeadingsStyle); cell = row.createCell(1); cell.setCellValue("Value"); cell.setCellStyle(columnHeadingsStyle); rowCount++; List<Long> timestamps = metricData.getTimestamps(); List<Double> values = metricData.getValues(); for (int i = 0; i < timestamps.size(); i++) { String timestamp = getCalendarTime(timestamps.get(i)); row = sheet.createRow((short) rowCount); row.createCell(0).setCellValue(timestamp); row.createCell(1).setCellValue(values.get(i)); rowCount++; } if (metricData.hasTotalCount()) { // Blank row for spacing/readability row = sheet.createRow((short) rowCount); cell = row.createCell(0); cell.setCellValue(""); rowCount++; row = sheet.createRow((short) rowCount); cell = row.createCell(0); cell.setCellValue("Total Count: "); cell.setCellStyle(columnHeadingsStyle); row.createCell(1).setCellValue(metricData.getTotalCount()); } sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); LOGGER.trace("EXITING: createSheet"); }
From source file:de.fraunhofer.sciencedataamanager.datamanager.SearchDefinitonExecutionDataManager.java
/** * * @param searchDefinitonExecutionList/*from w w w . j a v a 2s . c om*/ * @param outputStream * @throws Exception */ public void exportToExcel(LinkedList<SearchDefinitonExecution> searchDefinitonExecutionList, OutputStream outputStream) throws Exception { Workbook currentWorkBook = new HSSFWorkbook(); int currenSheetCount = 0; for (SearchDefinitonExecution searchDefinitonExecution : searchDefinitonExecutionList) { Sheet currentSheet = currentWorkBook.createSheet(); currentSheet.setFitToPage(true); currentSheet.setHorizontallyCenter(true); currentSheet.createFreezePane(0, 1); currentWorkBook.setSheetName(currenSheetCount, searchDefinitonExecution.getSystemInstance().getName()); Row headerRow = currentSheet.createRow(0); headerRow.setHeightInPoints(12.75f); headerRow.createCell(0).setCellValue("ID"); headerRow.createCell(1).setCellValue("Title"); headerRow.createCell(2).setCellValue("Identifier 1"); headerRow.createCell(3).setCellValue("Identifier 2"); headerRow.createCell(4).setCellValue("Identifier 3"); headerRow.createCell(5).setCellValue("Identifier 4"); headerRow.createCell(6).setCellValue("Url 1"); headerRow.createCell(7).setCellValue("Url 2"); headerRow.createCell(8).setCellValue("Text 1"); headerRow.createCell(9).setCellValue("Publication Name"); headerRow.createCell(10).setCellValue("Issue Name"); headerRow.createCell(11).setCellValue("Publish Date"); headerRow.createCell(12).setCellValue("Volume"); headerRow.createCell(13).setCellValue("Start Page"); headerRow.createCell(14).setCellValue("Issue Identifier"); CellStyle style = currentWorkBook.createCellStyle(); Font headerFont = currentWorkBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); headerRow.setRowStyle(style); Row currentRow = null; int rowNum = 1; for (ScientificPaperMetaInformation scientificPaperMetaInformation : searchDefinitonExecution .getScientificPaperMetaInformation()) { currentRow = currentSheet.createRow(rowNum); currentRow.createCell(0).setCellValue(scientificPaperMetaInformation.getID()); currentRow.createCell(1).setCellValue(scientificPaperMetaInformation.getTitle()); currentRow.createCell(2).setCellValue(scientificPaperMetaInformation.getIdentifier_1()); currentRow.createCell(3).setCellValue(scientificPaperMetaInformation.getIdentifier_2()); currentRow.createCell(4).setCellValue(scientificPaperMetaInformation.getIdentifier_3()); currentRow.createCell(5).setCellValue(scientificPaperMetaInformation.getIdentifier_4()); currentRow.createCell(6).setCellValue(scientificPaperMetaInformation.getUrl_1()); currentRow.createCell(7).setCellValue(scientificPaperMetaInformation.getUrl_2()); currentRow.createCell(8).setCellValue(scientificPaperMetaInformation.getText_1()); currentRow.createCell(9).setCellValue(scientificPaperMetaInformation.getSrcTitle()); currentRow.createCell(10).setCellValue(scientificPaperMetaInformation.getScrPublisherName()); currentRow.createCell(11).setCellValue(scientificPaperMetaInformation.getSrcPublicationDate()); currentRow.createCell(12).setCellValue(scientificPaperMetaInformation.getSrcVolume()); currentRow.createCell(13).setCellValue(scientificPaperMetaInformation.getSrcStartPage()); currentRow.createCell(14).setCellValue(scientificPaperMetaInformation.getScrIdentifier_1()); rowNum++; } currenSheetCount++; } currentWorkBook.write(outputStream); outputStream.close(); }
From source file:de.fraunhofer.sciencedataamanager.exampes.export.ExcelDataExport.java
/** * * @param dataToExport The objects gets all the values, which should * exported.//from www . j a v a2 s . com * @param outputStream * @throws Exception */ @Override public void export(Map<String, Map<String, List<Object>>> allConnectorsToExport, OutputStream outputStream) throws Exception { Workbook currentWorkBook = new HSSFWorkbook(); int currenSheetCount = 0; for (String currentKey : allConnectorsToExport.keySet()) { Map<String, List<Object>> dataToExport = allConnectorsToExport.get(currentKey); List<String> columns = new ArrayList<String>(dataToExport.keySet()); List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>(); int size = dataToExport.values().iterator().next().size(); for (int i = 0; i < size; i++) { Map<String, Object> row = new HashMap<String, Object>(); for (String column : columns) { row.put(column, dataToExport.get(column).get(i)); } rows.add(row); } //for (SearchDefinitonExecution searchDefinitonExecution : searchDefinitonExecutionList) { Sheet currentSheet = currentWorkBook.createSheet(); currentSheet.setFitToPage(true); currentSheet.setHorizontallyCenter(true); currentSheet.createFreezePane(0, 1); currentWorkBook.setSheetName(currenSheetCount, currentKey); Row headerRow = currentSheet.createRow(0); headerRow.setHeightInPoints(12.75f); int headerColumnIndex = 0; for (String currentColumn : columns) { headerRow.createCell(headerColumnIndex).setCellValue(currentColumn); headerColumnIndex++; } CellStyle style = currentWorkBook.createCellStyle(); Font headerFont = currentWorkBook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setAlignment(CellStyle.ALIGN_CENTER); style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFont(headerFont); headerRow.setRowStyle(style); Row currentRow = null; int rowNum = 1; int currentColum = 0; for (Map<String, Object> currentRow2 : rows) { currentRow = currentSheet.createRow(rowNum); for (String column : columns) { if (currentRow2.get(column) != null) { currentRow.createCell(currentColum).setCellValue(currentRow2.get(column).toString()); } currentColum++; } currentColum = 0; rowNum++; } currenSheetCount++; } currentWorkBook.write(outputStream); outputStream.close(); }