List of usage examples for org.apache.poi.xssf.usermodel XSSFFont getFontName
public String getFontName()
From source file:de.escnet.ExcelTable.java
License:Open Source License
private String styleFont(Map<String, String> styles, XSSFCell cell) { XSSFCellStyle cellStyle = cell.getCellStyle(); if (cellStyle != null) { short fontIndex = cellStyle.getFontIndex(); XSSFFont font = sheet.getWorkbook().getFontAt(fontIndex); if (font.getItalic()) { styles.put("font-style", "italic"); }//from www.java 2 s. c o m if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD) { styles.put("font-weight", "bold"); } styles.put("font", "" + font.getFontHeightInPoints() + "px " + font.getFontName()); if (FONT_COLORS) { String color = getHtmlColor(font.getXSSFColor()); if (color != null && !color.equals("#000000")) { return color; } } } return null; }
From source file:egovframework.rte.fdl.excel.EgovExcelXSSFServiceTest.java
License:Apache License
/** * [Flow #-6] ? : ? ?(?, ? )? // ww w.java2s . c om */ @Test public void testModifyCellAttribute() throws Exception { try { LOGGER.debug("testModifyCellAttribute start...."); StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testModifyCellAttribute.xlsx"); if (EgovFileUtil.isExistsFile(sb.toString())) { EgovFileUtil.delete(new File(sb.toString())); LOGGER.debug("Delete file....{}", sb.toString()); } Workbook wbTmp = new XSSFWorkbook(); wbTmp.createSheet(); // ? ? excelService.createWorkbook(wbTmp, sb.toString()); // ? XSSFWorkbook wb = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); LOGGER.debug("testModifyCellAttribute after loadWorkbook...."); Sheet sheet = wb.createSheet("cell test sheet2"); sheet.setColumnWidth((short) 3, (short) 200); // column Width CellStyle cs = wb.createCellStyle(); XSSFFont font = wb.createFont(); font.setFontHeight(16); font.setBoldweight((short) 3); font.setFontName("fixedsys"); cs.setFont(font); cs.setAlignment(XSSFCellStyle.ALIGN_RIGHT); // cell cs.setWrapText(true); for (int i = 0; i < 100; i++) { Row row = sheet.createRow(i); row.setHeight((short) 300); // row? height for (int j = 0; j < 5; j++) { Cell cell = row.createCell(j); cell.setCellValue(new XSSFRichTextString("row " + i + ", cell " + j)); cell.setCellStyle(cs); } } // ? FileOutputStream out = new FileOutputStream(sb.toString()); wb.write(out); out.close(); ////////////////////////////////////////////////////////////////////////// // ? XSSFWorkbook wbT = excelService.loadWorkbook(sb.toString(), new XSSFWorkbook()); Sheet sheetT = wbT.getSheet("cell test sheet2"); LOGGER.debug("getNumCellStyles : {}", wbT.getNumCellStyles()); XSSFCellStyle cs1 = (XSSFCellStyle) wbT.getCellStyleAt((short) (wbT.getNumCellStyles() - 1)); XSSFFont fontT = cs1.getFont(); LOGGER.debug("font getFontHeight : {}", fontT.getFontHeight()); LOGGER.debug("font getBoldweight : {}", fontT.getBoldweight()); LOGGER.debug("font getFontName : {}", fontT.getFontName()); LOGGER.debug("getAlignment : {}", cs1.getAlignment()); LOGGER.debug("getWrapText : {}", cs1.getWrapText()); for (int i = 0; i < 100; i++) { Row row1 = sheetT.getRow(i); for (int j = 0; j < 5; j++) { Cell cell1 = row1.getCell(j); LOGGER.debug("row {}, cell {} : {}", i, j, cell1.getRichStringCellValue()); assertEquals(320, fontT.getFontHeight()); assertEquals(400, fontT.getBoldweight()); LOGGER.debug("fontT.getBoldweight()? ? 400? ?"); assertEquals(XSSFCellStyle.ALIGN_RIGHT, cs1.getAlignment()); assertTrue(cs1.getWrapText()); } } } catch (Exception e) { LOGGER.error(e.toString()); throw new Exception(e); } finally { LOGGER.debug("testModifyCellAttribute end...."); } }
From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java
License:BSD License
public boolean areFontsEmpty(CellStyle style) { XSSFCellStyle newStyle = (XSSFCellStyle) style; XSSFFont font = newStyle.getFont(); if (font.getBold()) return false; if (font.getItalic()) return false; if (font.getUnderline() != XSSFFont.U_NONE) return false; if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE) return false; if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME)) return false; if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) { String colorString = getRGBString(font.getXSSFColor()); if (colorString != null) { return false; }/* w ww .ja v a2 s . com*/ } return true; }
From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java
License:BSD License
@Override public void writeFontProperties(XMLStreamWriter xmlWriter, CellStyle style) throws XMLStreamException { XSSFCellStyle newStyle = (XSSFCellStyle) style; XSSFFont font = newStyle.getFont(); if (font.getBold()) { xmlWriter.writeStartElement("font-weight"); xmlWriter.writeCharacters("bold"); xmlWriter.writeEndElement();/*from ww w.j ava2 s. co m*/ } if (font.getItalic()) { xmlWriter.writeStartElement("font-style"); xmlWriter.writeCharacters("italics"); xmlWriter.writeEndElement(); } if (font.getUnderline() != XSSFFont.U_NONE) { xmlWriter.writeStartElement("text-decoration"); xmlWriter.writeCharacters("underline"); xmlWriter.writeEndElement(); } if (font.getFontHeight() != XSSFFont.DEFAULT_FONT_SIZE) { xmlWriter.writeStartElement("font-size"); xmlWriter.writeCharacters(String.valueOf(font.getFontHeightInPoints()) + "pt"); xmlWriter.writeEndElement(); } if (!font.getFontName().equals(XSSFFont.DEFAULT_FONT_NAME)) { xmlWriter.writeStartElement("font-family"); xmlWriter.writeCharacters(String.valueOf(font.getFontName())); xmlWriter.writeEndElement(); } if (font.getColor() != XSSFFont.DEFAULT_FONT_COLOR) { String colorString = getRGBString(font.getXSSFColor()); if (colorString != null) { xmlWriter.writeStartElement("color"); xmlWriter.writeCharacters(colorString); xmlWriter.writeEndElement(); } } }