use of org.apache.poi.ss.usermodel.Font in project Robot-Scouter by SUPERCILEX.
the class SpreadsheetCache method getHeaderMetricRowHeaderStyle.
@Nullable
public CellStyle getHeaderMetricRowHeaderStyle() {
if (isUnsupportedDevice())
return null;
CellStyle rowHeaderStyle = createRowHeaderStyle();
Font font = createBaseHeaderFont();
font.setItalic(true);
font.setFontHeightInPoints((short) 14);
rowHeaderStyle.setFont(font);
return rowHeaderStyle;
}
use of org.apache.poi.ss.usermodel.Font in project poi by apache.
the class SSPerformanceTest method createStyles.
static Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style;
Font headerFont = wb.createFont();
headerFont.setFontHeightInPoints((short) 14);
headerFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(headerFont);
style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styles.put("header", style);
Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 12);
monthFont.setColor(IndexedColors.RED.getIndex());
monthFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
style.setFillPattern(FillPatternType.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;
}
use of org.apache.poi.ss.usermodel.Font in project poi by apache.
the class SheetUtil method getDefaultCharWidth.
/**
* Get default character width using the Workbook's default font
*
* @param wb the workbook to get the default character width from
* @return default character width in pixels
*/
@Internal
public static int getDefaultCharWidth(final Workbook wb) {
Font defaultFont = wb.getFontAt((short) 0);
AttributedString str = new AttributedString(String.valueOf(defaultChar));
copyAttributes(defaultFont, str, 0, 1);
TextLayout layout = new TextLayout(str.getIterator(), fontRenderContext);
return (int) layout.getAdvance();
}
use of org.apache.poi.ss.usermodel.Font in project poi by apache.
the class CalendarDemo method createStyles.
/**
* cell styles used for formatting calendar sheets
*/
private static Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
short borderColor = IndexedColors.GREY_50_PERCENT.getIndex();
CellStyle style;
Font titleFont = wb.createFont();
titleFont.setFontHeightInPoints((short) 48);
titleFont.setColor(IndexedColors.DARK_BLUE.getIndex());
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFont(titleFont);
styles.put("title", style);
Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 12);
monthFont.setColor(IndexedColors.WHITE.getIndex());
monthFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(monthFont);
styles.put("month", style);
Font dayFont = wb.createFont();
dayFont.setFontHeightInPoints((short) 14);
dayFont.setBold(true);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.TOP);
style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderLeft(BorderStyle.THIN);
style.setLeftBorderColor(borderColor);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
style.setFont(dayFont);
styles.put("weekend_left", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.TOP);
style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(borderColor);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
styles.put("weekend_right", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.TOP);
style.setBorderLeft(BorderStyle.THIN);
style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setLeftBorderColor(borderColor);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
style.setFont(dayFont);
styles.put("workday_left", style);
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.TOP);
style.setFillForegroundColor(IndexedColors.WHITE.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(borderColor);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
styles.put("workday_right", style);
style = wb.createCellStyle();
style.setBorderLeft(BorderStyle.THIN);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
styles.put("grey_left", style);
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(borderColor);
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(borderColor);
styles.put("grey_right", style);
return styles;
}
use of org.apache.poi.ss.usermodel.Font in project poi by apache.
the class CellStyleDetails method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
throw new IllegalArgumentException("Filename must be given");
}
Workbook wb = WorkbookFactory.create(new File(args[0]));
DataFormatter formatter = new DataFormatter();
for (int sn = 0; sn < wb.getNumberOfSheets(); sn++) {
Sheet sheet = wb.getSheetAt(sn);
System.out.println("Sheet #" + sn + " : " + sheet.getSheetName());
for (Row row : sheet) {
System.out.println(" Row " + row.getRowNum());
for (Cell cell : row) {
CellReference ref = new CellReference(cell);
System.out.print(" " + ref.formatAsString());
System.out.print(" (" + cell.getColumnIndex() + ") ");
CellStyle style = cell.getCellStyle();
System.out.print("Format=" + style.getDataFormatString() + " ");
System.out.print("FG=" + renderColor(style.getFillForegroundColorColor()) + " ");
System.out.print("BG=" + renderColor(style.getFillBackgroundColorColor()) + " ");
Font font = wb.getFontAt(style.getFontIndex());
System.out.print("Font=" + font.getFontName() + " ");
System.out.print("FontColor=");
if (font instanceof HSSFFont) {
System.out.print(renderColor(((HSSFFont) font).getHSSFColor((HSSFWorkbook) wb)));
}
if (font instanceof XSSFFont) {
System.out.print(renderColor(((XSSFFont) font).getXSSFColor()));
}
System.out.println();
System.out.println(" " + formatter.formatCellValue(cell));
}
}
System.out.println();
}
wb.close();
}
Aggregations