List of usage examples for org.apache.poi.ss.usermodel Font setStrikeout
void setStrikeout(boolean strikeout);
From source file:biz.webgate.dominoext.poi.component.kernel.WorkbookProcessor.java
License:Apache License
public void setCellValue(Sheet shProcess, int nRow, int nCol, Object objValue, boolean isFormula, PoiCellStyle pCellStyle) {//from w w w .j av a 2 s.c o m // Logger logCurrent = // LoggerFactory.getLogger(WorkbookProcessor.class.getCanonicalName()); try { Row rw = shProcess.getRow(nRow); if (rw == null) { // logCurrent.finest("Create Row"); rw = shProcess.createRow(nRow); } Cell c = rw.getCell(nCol); if (c == null) { // logCurrent.finest("Create Cell"); c = rw.createCell(nCol); } if (isFormula) { c.setCellFormula((String) objValue); } else { if (objValue instanceof Double) { c.setCellValue((Double) objValue); } else if (objValue instanceof Integer) { c.setCellValue((Integer) objValue); } else { if (objValue instanceof Date) { c.setCellValue((Date) objValue); } else { c.setCellValue("" + objValue); } } } // *** STYLE CONFIG Since V 1.1.7 *** if (pCellStyle != null) { checkStyleConstantValues(); if (pCellStyle.getCellStyle() != null) { c.setCellStyle(pCellStyle.getCellStyle()); } else { CellStyle style = shProcess.getWorkbook().createCellStyle(); if (pCellStyle.getAlignment() != null) style.setAlignment(m_StyleConstantValues.get(pCellStyle.getAlignment())); if (pCellStyle.getBorderBottom() != null) style.setBorderBottom(m_StyleConstantValues.get(pCellStyle.getBorderBottom())); if (pCellStyle.getBorderLeft() != null) style.setBorderLeft(m_StyleConstantValues.get(pCellStyle.getBorderLeft())); if (pCellStyle.getBorderRight() != null) style.setBorderRight(m_StyleConstantValues.get(pCellStyle.getBorderRight())); if (pCellStyle.getBorderTop() != null) style.setBorderTop(m_StyleConstantValues.get(pCellStyle.getBorderTop())); if (pCellStyle.getBottomBorderColor() != null) style.setBottomBorderColor( IndexedColors.valueOf(pCellStyle.getBottomBorderColor()).getIndex()); if (pCellStyle.getDataFormat() != null) { DataFormat format = shProcess.getWorkbook().createDataFormat(); style.setDataFormat(format.getFormat(pCellStyle.getDataFormat())); } if (pCellStyle.getFillBackgroundColor() != null) style.setFillBackgroundColor( IndexedColors.valueOf(pCellStyle.getFillBackgroundColor()).getIndex()); if (pCellStyle.getFillForegroundColor() != null) style.setFillForegroundColor( IndexedColors.valueOf(pCellStyle.getFillForegroundColor()).getIndex()); if (pCellStyle.getFillPattern() != null) style.setFillPattern(m_StyleConstantValues.get(pCellStyle.getFillPattern())); // Create a new font and alter it. Font font = shProcess.getWorkbook().createFont(); if (pCellStyle.getFontBoldweight() != null) font.setBoldweight(m_StyleConstantValues.get(pCellStyle.getFontBoldweight())); if (pCellStyle.getFontColor() != null) font.setColor(IndexedColors.valueOf(pCellStyle.getFontColor()).getIndex()); if (pCellStyle.getFontHeightInPoints() != 0) font.setFontHeightInPoints(pCellStyle.getFontHeightInPoints()); if (pCellStyle.getFontName() != null) font.setFontName(pCellStyle.getFontName()); if (pCellStyle.isFontItalic()) font.setItalic(pCellStyle.isFontItalic()); if (pCellStyle.isFontStrikeout()) font.setStrikeout(pCellStyle.isFontStrikeout()); if (pCellStyle.getFontUnderline() != null) font.setUnderline(m_StyleByteConstantValues.get(pCellStyle.getFontUnderline())); if (pCellStyle.getFontTypeOffset() != null) font.setTypeOffset(m_StyleConstantValues.get(pCellStyle.getFontTypeOffset())); // Set Font style.setFont(font); if (pCellStyle.isHidden()) style.setHidden(pCellStyle.isHidden()); if (pCellStyle.getIndention() != null) style.setIndention(m_StyleConstantValues.get(pCellStyle.getIndention())); if (pCellStyle.getLeftBorderColor() != null) style.setLeftBorderColor(IndexedColors.valueOf(pCellStyle.getLeftBorderColor()).getIndex()); if (pCellStyle.isLocked()) style.setLocked(pCellStyle.isLocked()); if (pCellStyle.getRightBorderColor() != null) style.setRightBorderColor( IndexedColors.valueOf(pCellStyle.getRightBorderColor()).getIndex()); if (pCellStyle.getRotation() != 0) style.setRotation(pCellStyle.getRotation()); if (pCellStyle.getTopBorderColor() != null) style.setTopBorderColor(IndexedColors.valueOf(pCellStyle.getTopBorderColor()).getIndex()); if (pCellStyle.getVerticalAlignment() != null) style.setVerticalAlignment(m_StyleConstantValues.get(pCellStyle.getVerticalAlignment())); if (pCellStyle.isWrapText()) style.setWrapText(pCellStyle.isWrapText()); c.setCellStyle(style); pCellStyle.setCellStyle(style); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:br.com.tecsinapse.dataio.style.TableCellStyle.java
License:LGPL
private void configFont(Font font) { font.setBold(isBold());//from w w w . j a v a 2 s .co m font.setItalic(isItalic()); font.setStrikeout(isStrikeout()); font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE); if (getFontSize() != null) { font.setFontHeightInPoints(fontSize.shortValue()); } if (getFontColor() != null) { if (font instanceof XSSFFont) { ((XSSFFont) font).setColor(new XSSFColor(toIndexedColorMap(fontColor))); } else { font.setColor(fontColor.getIndex()); } } }
From source file:br.com.tecsinapse.exporter.style.TableCellStyle.java
License:LGPL
private void configFont(Font font) { font.setBold(isBold());//from ww w . ja va 2 s.c o m font.setItalic(isItalic()); font.setStrikeout(isStrikeout()); font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE); if (getFontSize() != null) { font.setFontHeightInPoints(fontSize.shortValue()); } if (getFontColor() != null) { font.setColor(fontColor.getIndex()); } }
From source file:com.liferay.portlet.documentlibrary.action.EditEntryAction.java
License:Open Source License
public static void exportDocumentData(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws NumberFormatException, PortalException, SystemException { long file_id = 0; String fileEntryIds = ParamUtil.getString(resourceRequest, "fileEntryIds"); String[] fileentires = fileEntryIds.split(","); List<Long> tempResults = new ArrayList<Long>(); if (!fileEntryIds.isEmpty()) { if (fileentires[0].equals("true")) { for (int i = 1; i < fileentires.length; i++) { DLFileEntry FileEntry = DLFileEntryLocalServiceUtil .getDLFileEntry(Long.parseLong(fileentires[i])); file_id = FileEntry.getFileEntryId(); tempResults.add(file_id); }// w w w. j a v a 2 s . com } else { for (int i = 0; i < fileentires.length; i++) { DLFileEntry FileEntry = DLFileEntryLocalServiceUtil .getDLFileEntry(Long.parseLong(fileentires[i])); file_id = FileEntry.getFileEntryId(); tempResults.add(file_id); } } } try { HSSFWorkbook hwb = new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("Site Information"); org.apache.poi.ss.usermodel.Font font = hwb.createFont(); font.setFontHeightInPoints((short) 11); font.setFontName("Arial"); font.setItalic(false); font.setStrikeout(false); font.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); CellStyle style = hwb.createCellStyle(); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(HSSFColor.BLACK.index); style.setFont(font); CellStyle filterStyle = hwb.createCellStyle(); org.apache.poi.ss.usermodel.Font filterfont = hwb.createFont(); filterfont.setFontHeightInPoints((short) 9); filterfont.setFontName("Courier New"); filterfont.setItalic(false); filterfont.setStrikeout(false); filterfont.setBoldweight(org.apache.poi.ss.usermodel.Font.BOLDWEIGHT_BOLD); filterStyle.setFont(filterfont); filterStyle.setBorderBottom(CellStyle.BORDER_THIN); filterStyle.setBorderLeft(CellStyle.BORDER_THIN); filterStyle.setBorderTop(CellStyle.BORDER_THIN); filterStyle.setBorderRight(CellStyle.BORDER_THIN); HSSFRow rowhead = sheet.createRow((short) 2); rowhead.createCell((short) 0).setCellValue("S.No."); rowhead.createCell((short) 1).setCellValue("Title "); rowhead.createCell((short) 2).setCellValue("Site Name "); rowhead.createCell((short) 3).setCellValue("Category Type"); rowhead.createCell((short) 4).setCellValue("Com"); rowhead.createCell((short) 5).setCellValue("Upload Date"); rowhead.createCell((short) 6).setCellValue("File Type"); int index = 3; int sno = 0; for (int i = 0; i < tempResults.size(); i++) { sno++; DLFileEntry objdlfileentry = DLFileEntryLocalServiceUtil.getDLFileEntry(tempResults.get(i)); docs_customData objdocs_customData = null; try { objdocs_customData = docs_customDataLocalServiceUtil.getfileEntry(tempResults.get(i)); } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); } String com = ""; if (objdocs_customData != null) { com = objdocs_customData.getCom(); } String siteName = ""; if (objdocs_customData != null) { siteName = objdocs_customData.getSite(); } String doccategory = ""; if (objdocs_customData != null) { doccategory = objdocs_customData.getCategory(); } HSSFRow row = sheet.createRow((short) index); row.createCell((short) 0).setCellValue(sno); row.createCell((short) 1).setCellValue(objdlfileentry.getTitle()); row.createCell((short) 2).setCellValue(siteName); row.createCell((short) 3).setCellValue(doccategory); row.createCell((short) 4).setCellValue(com); row.createCell((short) 5).setCellValue(objdlfileentry.getModifiedDate()); row.createCell((short) 6).setCellValue(objdlfileentry.getMimeType()); index++; } resourceResponse.setContentType("application/vnd.ms-excel"); resourceResponse.addProperty("Content-Disposition", "attachment;filename=Document_Listing.xls"); OutputStream fileOut = resourceResponse.getPortletOutputStream(); hwb.write(fileOut); fileOut.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:eu.esdihumboldt.hale.io.xls.XLSCellStyles.java
License:Open Source License
/** * @param workbook the workbook of the cell * @param strikeOut true, if cell should be striked out * @return the normal cell style/*from ww w . j a va 2s . c o m*/ */ public static CellStyle getNormalStyle(Workbook workbook, boolean strikeOut) { // create cell style CellStyle cellStyle = workbook.createCellStyle(); DataFormat df = workbook.createDataFormat(); // set thin border around the cell cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); // set cell data format to text cellStyle.setDataFormat(df.getFormat("@")); // display multiple lines cellStyle.setWrapText(true); if (strikeOut) { // strike out font Font disabledFont = workbook.createFont(); disabledFont.setStrikeout(true); disabledFont.setColor(IndexedColors.GREY_40_PERCENT.getIndex()); cellStyle.setFont(disabledFont); } return cellStyle; }
From source file:eu.esdihumboldt.hale.io.xls.XLSCellStyles.java
License:Open Source License
/** * @param workbook the workbook of the cell * @param strikeOut true, if cell should be striked out * @return the highlighted cell style//from ww w . ja v a 2 s. c o m */ public static CellStyle getHighlightedStyle(Workbook workbook, boolean strikeOut) { // create highlight style for type cells CellStyle highlightStyle = workbook.createCellStyle(); DataFormat df = workbook.createDataFormat(); // set thin border around the cell highlightStyle.setBorderBottom(CellStyle.BORDER_THIN); highlightStyle.setBorderLeft(CellStyle.BORDER_THIN); highlightStyle.setBorderRight(CellStyle.BORDER_THIN); // set cell data format to text highlightStyle.setDataFormat(df.getFormat("@")); // display multiple lines highlightStyle.setWrapText(true); highlightStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); highlightStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); if (strikeOut) { Font disabledTypeFont = workbook.createFont(); disabledTypeFont.setStrikeout(true); disabledTypeFont.setColor(IndexedColors.BLACK.getIndex()); highlightStyle.setFont(disabledTypeFont); } return highlightStyle; }
From source file:gregchen.Simulation.java
License:Open Source License
private void initializeExcelFile() { //short rownum; //Create a Data folder if it does not already exist File theDir = new File("Data"); //if the directory does not exist, create it if(!theDir.exists()) {//from w w w . jav a2 s .c o m theDir.mkdir(); } // create a new file if(fileCount == 0) { File file = null; do { fileCount++; file = new File("Data/Data " + fileCount + ".xls"); }while(file.exists()); } try { excelOut = new FileOutputStream("Data/Data " + fileCount + ".xls"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } fileCount++; // create a new workbook wb = new HSSFWorkbook(); // create a new sheet s = wb.createSheet(); // declare a row object reference Row r = null; // declare a cell object reference Cell c = null; // create 3 cell styles CellStyle cs = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); CellStyle cs3 = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); // create 2 fonts objects Font f = wb.createFont(); Font f2 = wb.createFont(); //set font 1 to 12 point type f.setFontHeightInPoints((short) 12); //make it blue f.setColor( (short)0xc ); // make it bold //arial is the default font f.setBoldweight(Font.BOLDWEIGHT_BOLD); //set font 2 to 10 point type f2.setFontHeightInPoints((short) 10); //make it red f2.setColor( (short)Font.COLOR_RED ); //make it bold f2.setBoldweight(Font.BOLDWEIGHT_BOLD); f2.setStrikeout( true ); //set cell stlye cs.setFont(f); //set the cell format cs.setDataFormat(df.getFormat("#,##0.0")); //set a thin border cs2.setBorderBottom(cs2.BORDER_THIN); //fill w fg fill color cs2.setFillPattern((short) CellStyle.SOLID_FOREGROUND); //set the cell format to text see DataFormat for a full list cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text")); // set the font cs2.setFont(f2); // set the sheet name in Unicode wb.setSheetName(0, "Greg Chen"); // in case of plain ascii // wb.setSheetName(0, "HSSF Test"); // Make header cells r = s.createRow(0); c = r.createCell(7); c.setCellStyle(cs3); c.setCellValue("Initial number: " + initialNumber + " Number per release: " + numPerRelease + " Number Releases: " + numReleases + " Release Interval: " + releaseInterval + " Female lethal gene: " + fsRIDL); currentRow = 2; for (short cellnum = (short) 0; cellnum < 7; cellnum ++) { // create a numeric cell c = r.createCell(cellnum); // do some goofy math to demonstrate decimals String heading = null; switch(cellnum) { case 0: heading = "Day"; break; case 1: heading = "Total Population"; break; case 2: heading = "Male Population"; break; case 3: heading = "Female Population"; break; case 4: heading = "FF"; break; case 5: heading = "Ff"; break; case 6: heading = "ff"; break; } c.setCellValue(heading); // set this cell to the first cell style we defined c.setCellStyle(cs); // set the cell's string value to "Test" // make this column a bit wider if(cellnum > 0) { s.setColumnWidth((short) (cellnum), (short) ((300) / ((double) 1 / 20))); } r.setHeight((short) 800); } /* int rownum; for (rownum = (short) 0; rownum < 30; rownum++) { // create a row r = s.createRow(rownum); r.setHeight((short) 0x249); // } //draw a thick black border on the row at the bottom using BLANKS // advance 2 rows rownum++; rownum++; r = s.createRow(rownum); // define the third style to be the default // except with a thick black border at the bottom cs3.setBorderBottom(cs3.BORDER_THICK); */ // write the workbook to the output stream // close our file (don't blow out our file handles) }
From source file:guru.qas.martini.report.DefaultState.java
License:Apache License
protected void colorCompromisedThemes() { Collection<Cell> failed = statii.get("FAILED"); if (!failed.isEmpty()) { List<Row> rows = Lists.newArrayListWithExpectedSize(failed.size()); for (Cell cell : failed) { Row row = cell.getRow();//from w w w . ja v a 2 s . c o m rows.add(row); } Set<Cell> compromisedThemeCells = Sets.newHashSet(); Map<String, Collection<Cell>> themeMap = themes.asMap(); for (Map.Entry<String, Collection<Cell>> mapEntry : themeMap.entrySet()) { Collection<Cell> themeCells = mapEntry.getValue(); boolean compromised = false; for (Iterator<Cell> iterator = themeCells.iterator(); !compromised && iterator.hasNext();) { Cell themeCell = iterator.next(); Row row = themeCell.getRow(); compromised = rows.contains(row); } if (compromised) { compromisedThemeCells.addAll(themeCells); } } Set<String> compromisedThemes = Sets.newHashSet(); for (Cell themeCell : compromisedThemeCells) { String contents = themeCell.getStringCellValue(); if (null != contents) { Iterable<String> themes = Splitter.onPattern("\\s+").omitEmptyStrings().split(contents); Iterables.addAll(compromisedThemes, themes); } } for (String theme : compromisedThemes) { Collection<Cell> cells = themes.get(theme); for (Cell cell : cells) { CellStyle cellStyle = cell.getCellStyle(); Sheet sheet = cell.getSheet(); Workbook workbook = sheet.getWorkbook(); int originalFontIndex = cellStyle.getFontIndexAsInt(); Font originalFont = workbook.getFontAt(originalFontIndex); CellStyle clone = workbook.createCellStyle(); clone.cloneStyleFrom(cellStyle); Font font = workbook.findFont(true, IndexedColors.DARK_RED.getIndex(), originalFont.getFontHeight(), originalFont.getFontName(), originalFont.getItalic(), originalFont.getStrikeout(), originalFont.getTypeOffset(), originalFont.getUnderline()); if (null == font) { font = workbook.createFont(); font.setBold(true); font.setColor(IndexedColors.DARK_RED.getIndex()); font.setFontHeight(originalFont.getFontHeight()); font.setFontName(originalFont.getFontName()); font.setItalic(originalFont.getItalic()); font.setStrikeout(originalFont.getStrikeout()); font.setTypeOffset(originalFont.getTypeOffset()); font.setUnderline(originalFont.getUnderline()); } clone.setFont(font); cell.setCellStyle(clone); } } } }
From source file:guru.qas.martini.report.DefaultTraceabilityMatrix.java
License:Apache License
protected Font getHeaderFont(Workbook workbook) { Font font = workbook.findFont(true, // bold IndexedColors.BLACK.getIndex(), (short) 300, ARIAL, false, // italic false, // strikeout Font.SS_NONE, Font.U_NONE); if (null == font) { font = workbook.createFont();/*from w w w . ja v a 2 s . com*/ font.setBold(true); font.setColor(IndexedColors.BLACK.getIndex()); font.setFontHeight((short) 300); font.setFontName(ARIAL); font.setItalic(false); font.setStrikeout(false); font.setTypeOffset(Font.SS_NONE); font.setUnderline(Font.U_NONE); } return font; }
From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java
License:Apache License
private Font getFont(short fontIndex, AttributeSet attributeSet, Workbook wb) { Font font = null; String family = null;//from ww w . j a va 2s. c o m String sizeStr = null; short color = 0; boolean bold = false; boolean italic = false; boolean underline = false; boolean line_through = false; boolean sub = false; boolean sup = false; Enumeration<?> en = attributeSet.getAttributeNames(); while (en.hasMoreElements()) { Object key = en.nextElement(); String name = key.toString(); String attribute = attributeSet.getAttribute(key).toString(); switch (name) { case "font-weight": bold = attribute.equals("bold"); break; case "font-style": italic = attribute.equals("italic"); break; case "text-decoration": if (attribute.equals("underline")) { underline = true; } else if (attribute.equals("line-through")) { line_through = true; } break; case "font-family": family = attribute; break; case "font-size": sizeStr = attribute; break; case "color": Color fontColor = Utils.colorByName(attribute); if (fontColor == null) { try { fontColor = Utils.stringToColor(attribute); } catch (Exception ignored) { } } if (fontColor != null) { color = colorToIndex(wb, fontColor); } break; case "vertical-align": if (attribute.equals("sub")) { sub = true; } else if (attribute.equals("sup")) { sup = true; } break; } } if (family != null || bold || italic || underline || line_through || color > 0 || sizeStr != null || sub || sup) { font = wb.createFont(); if (fontIndex > 0) { Font parentFont = wb.getFontAt(fontIndex); if (parentFont != null) { font.setBold(parentFont.getBold()); font.setColor(parentFont.getColor()); try { font.setCharSet(parentFont.getCharSet()); } catch (Throwable ignored) { } font.setFontHeight(parentFont.getFontHeight()); font.setFontName(parentFont.getFontName()); font.setItalic(parentFont.getItalic()); font.setStrikeout(parentFont.getStrikeout()); font.setUnderline(parentFont.getUnderline()); font.setTypeOffset(parentFont.getTypeOffset()); } } if (family != null) { font.setFontName(family); } if (bold) { font.setBold(true); } if (italic) { font.setItalic(italic); } if (underline) { font.setUnderline(Font.U_SINGLE); } if (line_through) { font.setStrikeout(line_through); } if (color > 0) { font.setColor(color); } if (sizeStr != null) { short size = (short) Float.parseFloat(sizeStr); if (sizeStr.charAt(0) == '+' || sizeStr.charAt(0) == '-') { size = (short) (Content.pointToSize(font.getFontHeightInPoints()) + size); } font.setFontHeightInPoints(Content.sizeToPoints(size)); } if (sup) { font.setTypeOffset(Font.SS_SUPER); } else if (sub) { font.setTypeOffset(Font.SS_SUB); } } return font; }