List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle
CellStyle createCellStyle();
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 w ww . ja va2s . c o m*/ 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"); } } } }
From source file:Compras.generaCotizacion.java
void exel() { h = new Herramientas(this.user, 0); h.session(sessionPrograma);//from ww w. ja v a2 s . 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:contestTabulation.Setup.java
License:Open Source License
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity contestInfo = Retrieve.contestInfo(); GoogleCredential credential = new GoogleCredential.Builder().setJsonFactory(jsonFactory) .setTransport(httpTransport) .setClientSecrets((String) contestInfo.getProperty("OAuth2ClientId"), (String) contestInfo.getProperty("OAuth2ClientSecret")) .build().setFromTokenResponse(new JacksonFactory().fromString( ((Text) contestInfo.getProperty("OAuth2Token")).getValue(), GoogleTokenResponse.class)); String docName = null, docLevel = null; for (Level level : Level.values()) { docName = req.getParameter("doc" + level.getName()); if (docName != null) { docLevel = level.toString(); break; }/* w ww . j a va 2 s.c o m*/ } if (docLevel == null) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Spreadsheet creation request must have paramater document name parameter set"); return; } Query query = new Query("registration") .setFilter(new FilterPredicate("schoolLevel", FilterOperator.EQUAL, docLevel)) .addSort("schoolName", SortDirection.ASCENDING); List<Entity> registrations = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults()); Map<String, List<JSONObject>> studentData = new HashMap<String, List<JSONObject>>(); for (Entity registration : registrations) { String regSchoolName = ((String) registration.getProperty("schoolName")).trim(); String regStudentDataJSON = unescapeHtml4(((Text) registration.getProperty("studentData")).getValue()); JSONArray regStudentData = null; try { regStudentData = new JSONArray(regStudentDataJSON); } catch (JSONException e) { e.printStackTrace(); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } for (int i = 0; i < regStudentData.length(); i++) { if (!studentData.containsKey(regSchoolName)) { studentData.put(regSchoolName, new ArrayList<JSONObject>()); } try { studentData.get(regSchoolName).add(regStudentData.getJSONObject(i)); } catch (JSONException e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); e.printStackTrace(); return; } } } for (List<JSONObject> students : studentData.values()) { Collections.sort(students, new Comparator<JSONObject>() { @Override public int compare(JSONObject a, JSONObject b) { try { return a.getString("name").compareTo(b.getString("name")); } catch (JSONException e) { e.printStackTrace(); return 0; } } }); } Workbook workbook = new XSSFWorkbook(); XSSFCellStyle boldStyle = (XSSFCellStyle) workbook.createCellStyle(); Font boldFont = workbook.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); boldStyle.setFont(boldFont); Map<Subject, XSSFCellStyle> subjectCellStyles = new HashMap<Subject, XSSFCellStyle>(); for (Subject subject : Subject.values()) { final double ALPHA = .144; String colorStr = (String) contestInfo.getProperty("color" + subject.getName()); byte[] backgroundColor = new byte[] { Integer.valueOf(colorStr.substring(1, 3), 16).byteValue(), Integer.valueOf(colorStr.substring(3, 5), 16).byteValue(), Integer.valueOf(colorStr.substring(5, 7), 16).byteValue() }; // http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending byte[] borderColor = new byte[] { (byte) ((backgroundColor[0] & 0xff) * (1 - ALPHA)), (byte) ((backgroundColor[1] & 0xff) * (1 - ALPHA)), (byte) ((backgroundColor[2] & 0xff) * (1 - ALPHA)) }; XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); style.setFillBackgroundColor(new XSSFColor(backgroundColor)); style.setFillPattern(CellStyle.ALIGN_FILL); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(new XSSFColor(borderColor)); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(new XSSFColor(borderColor)); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(new XSSFColor(borderColor)); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(new XSSFColor(borderColor)); subjectCellStyles.put(subject, style); } Entry<String, List<JSONObject>>[] studentDataEntries = studentData.entrySet().toArray(new Entry[] {}); Arrays.sort(studentDataEntries, Collections.reverseOrder(new Comparator<Entry<String, List<JSONObject>>>() { @Override public int compare(Entry<String, List<JSONObject>> arg0, Entry<String, List<JSONObject>> arg1) { return Integer.compare(arg0.getValue().size(), arg1.getValue().size()); } })); for (Entry<String, List<JSONObject>> studentDataEntry : studentDataEntries) { Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(studentDataEntry.getKey())); Row row = sheet.createRow((short) 0); String[] columnNames = { "Name", "Grade", "N", "C", "M", "S" }; for (int i = 0; i < columnNames.length; i++) { String columnName = columnNames[i]; Cell cell = row.createCell(i); cell.setCellValue(columnName); cell.setCellStyle(boldStyle); CellUtil.setAlignment(cell, workbook, CellStyle.ALIGN_CENTER); } int longestNameLength = 7; int rowNum = 1; for (JSONObject student : studentDataEntry.getValue()) { try { row = sheet.createRow((short) rowNum); row.createCell(0).setCellValue(student.getString("name")); row.createCell(1).setCellValue(student.getInt("grade")); for (Subject subject : Subject.values()) { String value = student.getBoolean(subject.toString()) ? "" : "X"; Cell cell = row.createCell(Arrays.asList(columnNames).indexOf(subject.toString())); cell.setCellValue(value); cell.setCellStyle(subjectCellStyles.get(subject)); } if (student.getString("name").length() > longestNameLength) { longestNameLength = student.getString("name").length(); } rowNum++; } catch (JSONException e) { e.printStackTrace(); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); return; } } sheet.createFreezePane(0, 1, 0, 1); // sheet.autoSizeColumn((short) 0); Not supported by App Engine sheet.setColumnWidth((short) 0, (int) (256 * longestNameLength * 1.1)); } Drive drive = new Drive.Builder(httpTransport, jsonFactory, credential) .setApplicationName("contestTabulation").build(); File body = new File(); body.setTitle(docName); body.setMimeType("application/vnd.google-apps.spreadsheet"); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); workbook.write(outStream); ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); InputStreamContent content = new InputStreamContent( "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", inStream); drive.files().insert(body, content).execute(); workbook.close(); }
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 }/*from ww w. j ava2 s.co m*/ } }
From source file:controller.VisitasController.java
public void centerRow(Workbook wb, Row row) { CellStyle style = wb.createCellStyle(); style.setAlignment(HorizontalAlignment.CENTER); for (int i = 0; i < row.getLastCellNum(); i++) { if (row.getCell(i) != null) { row.getCell(i).setCellStyle(style);//Set the sty;e }/*from w ww . j av a 2s.c o m*/ } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private XSSFCellStyle getXSSFCellStyleValues(Workbook worbook, TypeValues typeValue, TypeUnits typeUnit) { XSSFCellStyle style = (XSSFCellStyle) worbook.createCellStyle(); XSSFFont font = (XSSFFont) worbook.createFont(); font.setBold(true);/*w ww .j a v a 2 s .c o m*/ font.setColor(new XSSFColor(Color.WHITE)); style.setAlignment(HorizontalAlignment.CENTER); switch (typeValue) { case VALUES: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.BLUE.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.BLUE.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.BLUE)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.CYAN)); break; } break; case UNITS: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.RED.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.RED.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.ORANGE)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.YELLOW)); break; } break; case U_E: switch (typeUnit) { case MTH: style.setFillForegroundColor(new XSSFColor(Color.GRAY.darker())); break; case QRT: style.setFillForegroundColor(new XSSFColor(Color.GREEN.darker().darker())); break; case YTD: style.setFillForegroundColor(new XSSFColor(Color.GRAY)); break; case MAT: style.setFillForegroundColor(new XSSFColor(Color.LIGHT_GRAY)); break; } break; } style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(font); return style; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private HSSFCellStyle getHSSFCellStyleValue(Workbook worbook, TypeValues typeValue, TypeUnits typeUnit) { HSSFCellStyle style = (HSSFCellStyle) worbook.createCellStyle(); HSSFFont font = (HSSFFont) worbook.createFont(); HSSFPalette palette = ((HSSFWorkbook) worbook).getCustomPalette(); font.setColor(HSSFColor.WHITE.index); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); switch (typeValue) { case VALUES:// w ww .j ava 2 s . co m switch (typeUnit) { case MTH: style.setFillForegroundColor(HSSFColor.DARK_BLUE.index); break; case QRT: style.setFillForegroundColor(HSSFColor.DARK_BLUE.index); palette.setColorAtIndex(HSSFColor.DARK_BLUE.index, (byte) 0, (byte) 0, (byte) 102); break; case YTD: style.setFillForegroundColor(HSSFColor.BLUE.index); break; case MAT: style.setFillForegroundColor(HSSFColor.AQUA.index); break; } break; case UNITS: switch (typeUnit) { case MTH: style.setFillForegroundColor(HSSFColor.RED.index); break; case QRT: style.setFillForegroundColor(HSSFColor.DARK_RED.index); break; case YTD: style.setFillForegroundColor(HSSFColor.ORANGE.index); break; case MAT: style.setFillForegroundColor(HSSFColor.YELLOW.index); break; } break; case U_E: switch (typeUnit) { case MTH: style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); break; case QRT: style.setFillForegroundColor(HSSFColor.DARK_GREEN.index); break; case YTD: style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index); break; case MAT: style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); break; } break; } style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); style.setFont(font); return style; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private XSSFCellStyle getXSSFCellStyleHeaderData(Workbook workbook) { XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); XSSFFont font = (XSSFFont) workbook.createFont(); font.setBold(true);//w ww.j a v a 2 s. co m font.setColor(new XSSFColor(Color.WHITE)); style.setAlignment(HorizontalAlignment.CENTER); style.setFillForegroundColor(new XSSFColor(Color.GRAY)); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); style.setFont(font); return style; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private HSSFCellStyle getHSSFCellStyleHeaderData(Workbook worbook) { HSSFCellStyle style = (HSSFCellStyle) worbook.createCellStyle(); HSSFFont font = (HSSFFont) worbook.createFont(); font.setBoldweight((short) 2); font.setColor(HSSFColor.WHITE.index); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); style.setFillForegroundColor(HSSFColor.GREY_50_PERCENT.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); return style; }
From source file:Data.Database.java
public void dumpExcel() throws FileNotFoundException, IOException { //Workbook wb = new HSSFWorkbook(); Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet("leaguedata"); // set headers on excel sheet Row row = sheet.createRow((short) 0); String headers[] = new String[] { "Team", "Player", "Position", "Age", "Yrs Played", "GP", "G", "A", "PTS", "+/-", "STP", "SOG", "SH%", "Hits", "Blocks", "TOI", "G/60", "A/60", "PTS/60", "STP/60", "SOG/60", "Hits/60", "Blocks/60" }; for (int i = 0; i < headers.length; i++) { Cell cell = row.createCell(i);/*from w w w .j av a 2s . c om*/ cell.setCellValue(createHelper.createRichTextString(headers[i])); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cell.setCellStyle(cellStyle); } // add player data int track = 2; // // dump ALL players!!!!! // for (Map.Entry<String, Player> entry : players.entrySet()){ // Row newrow = sheet.createRow((short)track); // entry.getValue().dumpExcel(newrow, "null"); // track++; // } // // // Write the output to a file // FileOutputStream fileOut = new FileOutputStream("RFHL_allplayers.xlsx"); // wb.write(fileOut); // fileOut.close(); // dump fantasy teams!!! for (int i = 0; i < fh_teams.size(); i++) { track = fh_teams.get(i).dumpExcel(sheet, track); track++; } // Write the output to a file FileOutputStream fileOut = new FileOutputStream("RFHL.xlsx"); wb.write(fileOut); fileOut.close(); }