List of usage examples for org.apache.poi.ss.usermodel Workbook createFont
Font createFont();
From source file:com.wabacus.system.assistant.StandardExcelAssistant.java
License:Open Source License
public CellStyle getTitleCellStyleForStandardExcel(Workbook workbook) { CellStyle cs = workbook.createCellStyle(); cs.setBorderTop(CellStyle.BORDER_THIN); cs.setBorderLeft(CellStyle.BORDER_THIN); cs.setBorderBottom(CellStyle.BORDER_THIN); cs.setBorderRight(CellStyle.BORDER_THIN); cs.setWrapText(true);//from w ww . j av a 2 s . com cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cs.setAlignment(CellStyle.ALIGN_CENTER); cs.setFillPattern(CellStyle.SOLID_FOREGROUND); cs.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 10); cs.setFont(font); //cs.setUserStyleName("wabacus_title_rowstyle");// return cs; }
From source file:com.wabacus.system.assistant.StandardExcelAssistant.java
License:Open Source License
public CellStyle getDataCellStyleForStandardExcel(Workbook workbook) { CellStyle cs = workbook.createCellStyle(); cs.setBorderTop(CellStyle.BORDER_THIN); cs.setBorderLeft(CellStyle.BORDER_THIN); cs.setBorderBottom(CellStyle.BORDER_THIN); cs.setBorderRight(CellStyle.BORDER_THIN); cs.setWrapText(true);// w ww .j a v a 2s .com cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 10); cs.setFont(font); return cs; }
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;/*from w ww . j av a 2 s . c om*/ Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 14); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); style = wb.createCellStyle(); 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.webbfontaine.valuewebb.report.utils.cellStyles.CellStyleUtils.java
License:Open Source License
public static CellStyle cellStyle(Workbook workBook, CellType cellType) { CellStyle cellStyle = workBook.createCellStyle(); if (!Color.NO_COLOR.equals(cellType.getColor())) { Font font = workBook.createFont(); font.setFontName("Arial"); font.setColor(cellType.getColor().index()); cellStyle.setFont(font);//from w w w . j a v a 2 s .c om } if (!Alignment.NO_ALIGNMENT.equals(cellType.getHorizontalAlignment())) { cellStyle.setAlignment(cellType.getHorizontalAlignment().index()); } if (!Alignment.NO_ALIGNMENT.equals(cellType.getVerticalAlignment())) { cellStyle.setVerticalAlignment(cellType.getVerticalAlignment().index()); } if (!Format.NO_FORMAT.equals(cellType.getFormat())) { CreationHelper creationHelper = workBook.getCreationHelper(); cellStyle.setDataFormat(creationHelper.createDataFormat().getFormat(cellType.getFormat().text())); } setCellBorders(cellStyle); return cellStyle; }
From source file:com.ykun.commons.utils.excel.ExcelUtils.java
License:Apache License
/** * ??// w w w . ja v a 2s . com * * @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(); // ?/*from w w w . j a va 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(); // ?/*from ww w.j ava 2 s . 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:com.zxy.commons.poi.excel.ExcelUtils.java
License:Apache License
/** * export excel/*from www . ja v a 2 s.c om*/ * * @param sheetName sheet name * @param table table * @return Workbook */ @SuppressWarnings("PMD.ShortVariable") private static Workbook exportExcel(String sheetName, Table<Integer, String, String> table) { Set<Integer> tableRows = table.rowKeySet(); Set<String> tableColumns = table.columnKeySet(); // excel Workbook wb = new HSSFWorkbook(); // sheet?? Sheet sheet = wb.createSheet(sheetName); // ???n? /*for (int i = 0; i < keys.length; i++) { sheet.setColumnWidth((short) i, (short) (35.7 * 150)); }*/ // Row row = sheet.createRow((short) 0); // ??? CellStyle cs = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); // ? Font f1 = wb.createFont(); Font f2 = wb.createFont(); // ???? f1.setFontHeightInPoints((short) 10); f1.setColor(IndexedColors.BLACK.getIndex()); f1.setBold(true); // ?? f2.setFontHeightInPoints((short) 10); f2.setColor(IndexedColors.BLACK.getIndex()); // Font f3=wb.createFont(); // f3.setFontHeightInPoints((short) 10); // f3.setColor(IndexedColors.RED.getIndex()); // ????? cs.setFont(f1); cs.setBorderLeft(BorderStyle.THIN); cs.setBorderRight(BorderStyle.THIN); cs.setBorderTop(BorderStyle.THIN); cs.setBorderBottom(BorderStyle.THIN); cs.setAlignment(HorizontalAlignment.CENTER); // ??? cs2.setFont(f2); cs2.setBorderLeft(BorderStyle.THIN); cs2.setBorderRight(BorderStyle.THIN); cs2.setBorderTop(BorderStyle.THIN); cs2.setBorderBottom(BorderStyle.THIN); cs2.setAlignment(HorizontalAlignment.CENTER); // ?? int i = 0; for (String tableColumn : tableColumns) { Cell cell = row.createCell(i); cell.setCellValue(tableColumn); cell.setCellStyle(cs); i++; } // ?? for (Integer tableRow : tableRows) { // Row ,Cell , Row Cell 0 // sheet checkArgument(tableRow > 0, "Row index must be greater than zero!"); Row row1 = sheet.createRow(tableRow); // row Map<String, String> item = table.row(tableRow); int j = 0; for (Map.Entry<String, String> entry : item.entrySet()) { // for(String v:item.keySet()){ // System.out.println(tableRow + "-" + v + "-" + item.get(v)); Cell cell = row1.createCell(j); cell.setCellValue(entry.getValue()); cell.setCellStyle(cs2); j++; } } return wb; }
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 . ja v 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.avanceSurtido.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: h = new Herramientas(this.user, 0); h.session(sessionPrograma);//from ww w. ja v a 2 s. com File archivoXLS = null; 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) { 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("Avance de pedidos"); Font font = libro.createFont(); font.setFontHeightInPoints((short) 24); font.setFontName("Arial"); font.setItalic(false); font.setBold(true); // Fonts are set into a style so create a new one to use. CellStyle style = libro.createCellStyle(); style.setFont(font); 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(2, 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("Modelo:"); r4.createCell(1).setCellValue("" + ord.getModelo()); hoja.createRow(5).createCell(0).setCellValue( "**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************"); Row r6 = hoja.createRow(6); r6.createCell(0).setCellValue("Partida"); r6.createCell(1).setCellValue("sub"); r6.createCell(2).setCellValue("Descripcion"); r6.createCell(3).setCellValue("Hoj"); r6.createCell(4).setCellValue("Mec"); r6.createCell(5).setCellValue("Sus"); r6.createCell(6).setCellValue("Ele"); r6.createCell(7).setCellValue("Can"); r6.createCell(8).setCellValue("Med"); r6.createCell(9).setCellValue("Folio"); r6.createCell(10).setCellValue("Codigo"); r6.createCell(11).setCellValue("Origen"); r6.createCell(12).setCellValue("Proveedor"); r6.createCell(13).setCellValue("Cant C."); r6.createCell(14).setCellValue("C/U Comprado"); r6.createCell(15).setCellValue("Plazo"); r6.createCell(16).setCellValue("Pedido"); r6.createCell(17).setCellValue("F. Pedido"); r6.createCell(18).setCellValue("Entradas"); r6.createCell(19).setCellValue("Devoluciones"); r6.createCell(20).setCellValue("Pendientes"); r6.createCell(21).setCellValue("No Factura"); hoja.createRow(7).createCell(0).setCellValue( "**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************"); session.close(); if (t_datos.getRowCount() > 0) { for (int i = 0; i < t_datos.getRowCount(); i++) { Row fila = hoja.createRow(i + 8); for (int j = 1; j < t_datos.getColumnCount(); j++) { if (j > 3 && j < 8) { if ((boolean) t_datos.getValueAt(i, j) == true) fila.createCell(j - 1).setCellValue(""); else fila.createCell(j - 1).setCellValue(""); } else { if (t_datos.getValueAt(i, j) != null) fila.createCell(j - 1).setCellValue("" + t_datos.getValueAt(i, j)); else fila.createCell(j - 1).setCellValue(""); } } } } libro.write(archivo); archivo.close(); Desktop.getDesktop().open(archivoXLS); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto"); } } } }