List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setTopBorderColor
public void setTopBorderColor(XSSFColor color)
From source file:br.com.techne.gluonsoft.eowexport.builder.ExcelBuilder.java
License:Apache License
/** * cria borda da tabela//from w w w .jav a 2s .c o m * @param wb * @return */ private static XSSFCellStyle createBorderedStyle(XSSFWorkbook wb) { XSSFCellStyle style = wb.createCellStyle(); 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()); return style; }
From source file:com.hauldata.dbpa.file.book.XlsxTargetSheet.java
License:Apache License
/** * Translate styling to workbook CellStyle. * * @param stylesUsed tracks the styles that have been used in the workbook; it will be updated * @param fontsUsed tracks the fonts that have been used in the workbook; it may be updated * @param colorsUsed tracks the colors that have been used in the workbook; it may be updated *///from w w w .j a v a 2s . c o m public CellStyle getCellStyle(SXSSFWorkbook book, Map<StylesWithFormatting, XSSFCellStyle> stylesUsed, Map<FontStyles, XSSFFont> fontsUsed, Map<Integer, XSSFColor> colorsUsed) { XSSFCellStyle cellStyle = stylesUsed.get(this); if (cellStyle != null) { return cellStyle; } cellStyle = (XSSFCellStyle) book.createCellStyle(); cellStyle.cloneStyleFrom(book.getCellStyleAt(formatIndex)); if (styles.bottomBorder.style != null) { cellStyle.setBorderBottom(resolveBorderStyle(styles.bottomBorder)); } if (styles.leftBorder.style != null) { cellStyle.setBorderLeft(resolveBorderStyle(styles.leftBorder)); } if (styles.rightBorder.style != null) { cellStyle.setBorderRight(resolveBorderStyle(styles.rightBorder)); } if (styles.topBorder.style != null) { cellStyle.setBorderTop(resolveBorderStyle(styles.topBorder)); } if (styles.bottomBorder.color != null) { cellStyle.setBottomBorderColor(getColor(styles.bottomBorder.color, book, colorsUsed)); } if (styles.leftBorder.color != null) { cellStyle.setLeftBorderColor(getColor(styles.leftBorder.color, book, colorsUsed)); } if (styles.rightBorder.color != null) { cellStyle.setRightBorderColor(getColor(styles.rightBorder.color, book, colorsUsed)); } if (styles.topBorder.color != null) { cellStyle.setTopBorderColor(getColor(styles.topBorder.color, book, colorsUsed)); } if (styles.backgroundColor != null) { cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); cellStyle.setFillForegroundColor(getColor(styles.backgroundColor, book, colorsUsed)); } if (styles.textAlign != null) { cellStyle.setAlignment(styles.textAlign); } if (!styles.font.areDefault()) { cellStyle.setFont(getFont(styles.font, book, fontsUsed, colorsUsed)); } stylesUsed.put(this, cellStyle); return cellStyle; }
From source file:com.l3.info.magenda.emplois_du_temps.Workbook.java
public void initialiserPalettedestyle(XSSFWorkbook workbook) { liste_des_styles = new HashMap<>(); XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); style.setBorderBottom(BorderStyle.MEDIUM); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.MEDIUM); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(BorderStyle.MEDIUM); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(BorderStyle.MEDIUM); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); liste_des_styles.put("nom_du_jour", style); style = (XSSFCellStyle) workbook.createCellStyle(); style.setBorderBottom(BorderStyle.MEDIUM); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.MEDIUM); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(BorderStyle.DASHED); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(BorderStyle.MEDIUM); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); liste_des_styles.put("case_gauche_jour", style); style = (XSSFCellStyle) workbook.createCellStyle(); style.setBorderBottom(BorderStyle.MEDIUM); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(BorderStyle.DASHED); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(BorderStyle.MEDIUM); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(BorderStyle.MEDIUM); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); liste_des_styles.put("case_droite_jour", style); }
From source file:com.l3.info.magenda.emplois_du_temps.Workbook.java
public void addCellStyle(String nom, Categorie cat) { XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle(); XSSFColor border = new XSSFColor(cat.getBorder()); style.setBorderBottom(BorderStyle.MEDIUM); style.setBottomBorderColor(border);// w w w . j a va 2 s. co m style.setBorderLeft(BorderStyle.MEDIUM); style.setLeftBorderColor(border); style.setBorderRight(BorderStyle.MEDIUM); style.setRightBorderColor(border); style.setBorderTop(BorderStyle.MEDIUM); style.setTopBorderColor(border); style.setWrapText(true); style.setVerticalAlignment(VerticalAlignment.CENTER); style.setFillForegroundColor(new XSSFColor(cat.getBackground())); XSSFFont font = workbook.createFont(); font.setColor(new XSSFColor(cat.getForeground())); style.setFont(font); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); liste_des_styles.put("Style_" + nom, style); }
From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java
License:Open Source License
protected XSSFCellStyle getCellStyle(int border, Font font) { XSSFCellStyle style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); // new line style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); if ((border & BORDER_BOTTOM) > 0) style.setBorderBottom(CellStyle.BORDER_DOUBLE); else/* w ww. jav a 2s . co m*/ style.setBorderBottom(CellStyle.BORDER_THIN); if ((border & BORDER_LEFT) > 0) style.setBorderLeft(CellStyle.BORDER_DOUBLE); else style.setBorderLeft(CellStyle.BORDER_THIN); if ((border & BORDER_RIGHT) > 0) style.setBorderRight(CellStyle.BORDER_DOUBLE); else style.setBorderRight(CellStyle.BORDER_THIN); if ((border & BORDER_TOP) > 0) style.setBorderTop(CellStyle.BORDER_DOUBLE); else style.setBorderTop(CellStyle.BORDER_THIN); if (font != null) style.setFont(font); return style; }
From source file:com.sec.ose.osi.report.standard.ISheetTemplate.java
License:Open Source License
/** * @param color/*from ww w . j a va 2 s . c om*/ * @param font * @return CellStyle */ protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) { XSSFCellStyle style = wb.createCellStyle(); style.setFillForegroundColor(color); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); style.setWrapText(true); // new line style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); if (font != null) style.setFont(font); return style; }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.AbstractSeccionXLS.java
License:Apache License
public void addBorders(XSSFWorkbook wb, XSSFCellStyle cellStyle, short borderType) { cellStyle.setBorderBottom(borderType); cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderLeft(borderType); cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderRight(borderType); cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); cellStyle.setBorderTop(borderType);//from ww w . j a v a 2s . c om cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); }
From source file:com.tikal.tallerWeb.servicio.reporte.cliente.AbstractSeccionXLS.java
License:Apache License
public void paintBorder(XSSFWorkbook wb, Sheet sheet, short borderType, BordeSeccion borde) { for (int i = borde.getUpperRow(); i <= borde.getLowerRow(); i++) { Row row = sheet.getRow(i);// w ww . j a v a 2 s . c o m for (int j = borde.getLeftColumn(); j <= borde.getRightColumn(); j++) { if (i == borde.getUpperRow() || i == borde.getLowerRow() || j == borde.getLeftColumn() || j == borde.getRightColumn()) { Cell cell = row.getCell(j); XSSFCellStyle actual = (XSSFCellStyle) cell.getCellStyle(); XSSFCellStyle nuevo = wb.createCellStyle(); nuevo.cloneStyleFrom(actual); if (i == borde.getUpperRow()) { nuevo.setBorderTop(borderType); nuevo.setTopBorderColor(IndexedColors.BLACK.getIndex()); } if (i == borde.getLowerRow()) { nuevo.setBorderBottom(borderType); nuevo.setBottomBorderColor(IndexedColors.BLACK.getIndex()); } if (j == borde.getLeftColumn()) { nuevo.setBorderLeft(borderType); nuevo.setLeftBorderColor(IndexedColors.BLACK.getIndex()); } if (j == borde.getRightColumn()) { nuevo.setBorderRight(borderType); nuevo.setRightBorderColor(IndexedColors.BLACK.getIndex()); } cell.setCellStyle(nuevo); } } } }
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; }//from ww w. j av a 2 s. c om } 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:document.ExcelDocumentStyles.java
private void withBorder(XSSFCellStyle style) { style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(borderColor); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(borderColor); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(borderColor); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(borderColor); }