Example usage for org.apache.poi.ss.usermodel Font setBold

List of usage examples for org.apache.poi.ss.usermodel Font setBold

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Font setBold.

Prototype

public void setBold(boolean bold);

Source Link

Usage

From source file:Controller.Sonstiges.ExcelController.java

private void makeTitleOfPage() throws IOException {

    this.sheet.addMergedRegion(new CellRangeAddress(0, 3, 0, 13));
    this.row = this.sheet.createRow(0);
    XSSFCell cell2 = this.row.createCell(0);
    String title = "Inprotuc Datenbank | Informationen zur Personen \nSuchkriterien: ";
    ArrayList<String> array2 = this.model.getQueryInfo();
    ArrayList<String> array = this.deleteEmptyValueOArray(array2);
    String info = "";
    if (array.size() == 2) {
        info = array.get(0) + " / " + array.get(1) + ".";
    }/*from  ww w  .jav a 2 s  .c  o  m*/
    if (array.size() == 4) {
        info = array.get(0) + "/" + array.get(1) + ", ";
        info = info + array.get(2) + "/" + array.get(3) + ".";
    }
    if (array.size() == 6) {
        info = array.get(0) + "/" + array.get(1) + ", ";
        info = info + array.get(2) + "/" + array.get(3) + ", ";
        info = info + array.get(4) + "/" + array.get(5) + ".";
    }
    cell2.setCellValue(title + info);
    CellStyle cellStyle = this.wb.createCellStyle();
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellStyle.setAlignment(HorizontalAlignment.LEFT);
    // font 
    Font font = this.wb.createFont();
    font.setFontHeightInPoints((short) 14);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBold(true);
    font.setColor(HSSFColor.BLACK.index);

    cellStyle.setFont(font);
    cell2.setCellStyle(cellStyle);

}

From source file:Controller.Sonstiges.ExcelController.java

private void makeTitleOfTable() {
    this.row = this.sheet.createRow(this.firstRow);
    CellStyle cellStyle = this.wb.createCellStyle();
    // font //from w  w  w . j  a  v a 2 s.  c  o m
    Font font = this.wb.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName(HSSFFont.FONT_ARIAL);

    font.setBold(true);
    font.setColor(HSSFColor.BLACK.index);

    cellStyle.setFont(font);
    this.saveDataInExcel(0, "Urz", cellStyle);
    this.saveDataInExcel(1, "Vorname", cellStyle);
    this.saveDataInExcel(2, "Name", cellStyle);
    this.saveDataInExcel(3, "Fakultt", cellStyle);
    this.saveDataInExcel(4, "Geburtsdatum", cellStyle);
    this.saveDataInExcel(5, "E-Mail", cellStyle);
    this.saveDataInExcel(6, "Telefonnummer", cellStyle);
    this.saveDataInExcel(7, "Aktivitten-ID", cellStyle);
    this.saveDataInExcel(8, "Aktivittenname", cellStyle);
    this.saveDataInExcel(9, "Zeitraum", cellStyle);
    this.saveDataInExcel(10, "Art", cellStyle);
    this.saveDataInExcel(11, "Durchfhrung", cellStyle);
    this.saveDataInExcel(12, "Bemerkung", cellStyle);
    this.saveDataInExcel(13, "Status", cellStyle);

}

From source file:cv_extractor.DocReader.java

protected static void generateExcel(String directory, String fileName) {
    XSSFWorkbook workbook = new XSSFWorkbook();

    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Email Address");

    //Create CellStyle for header (First row)
    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    Font font = sheet.getWorkbook().createFont();
    font.setBold(true);
    font.setFontHeightInPoints((short) 16);
    cellStyle.setFont(font);/* www  . j a  v  a2  s .  co  m*/

    //Create first row (Header)
    Row header = sheet.createRow(0);

    //Creating a cell (Only one required, for single attribute E-mail)
    Cell cellTitle = header.createCell(1);
    cellTitle.setCellStyle(cellStyle);
    cellTitle.setCellValue("E-Mail");

    //Counter to use while creating further rows, starting from row 1
    int rowNum = 1;

    //Iterate over data and write to sheet   
    Iterator<String> iterator = data.iterator();

    while (iterator.hasNext()) {
        //Create a row for each E-mail string
        Row row = sheet.createRow(rowNum++);

        //Create a cell to put the E-mail string
        Cell cell = row.createCell(1);

        //Put value in the cell
        cell.setCellValue(iterator.next());
    }

    try {
        //Write the workbook in file system

        if (fileName.equals("")) {
            fileName = "Email List";
        }

        FileOutputStream out = new FileOutputStream(new File(directory + "/" + fileName + ".xlsx"));
        workbook.write(out);
        out.close();

        JOptionPane.showMessageDialog(null, "File generated !");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.jlo.talendcomp.excel.SpreadsheetFile.java

License:Apache License

/**
 * adds a font to the workbook//from   w  w w  .j a  va 2s .  c o  m
 * @param family like Arial
 * @param height like 8,9,10,12,14...
 * @param bui with "b"=bold, "u"=underlined, "i"=italic and all combinations as String
 * @param color color index
 */
public void addStyle(String styleName, String fontFamily, String fontHeight, String fontDecoration,
        String fontColor, String bgColor, String textAlign, boolean buttomBorder) {
    if (styleName != null && styleName.isEmpty() == false) {
        Font f = workbook.createFont();
        if (fontFamily != null && fontFamily.isEmpty() == false) {
            f.setFontName(fontFamily);
        }
        if (fontHeight != null && fontHeight.isEmpty() == false) {
            short height = Short.parseShort(fontHeight);
            if (height > 0) {
                f.setFontHeightInPoints(height);
            }
        }
        if (fontDecoration != null && fontDecoration.isEmpty() == false) {
            if (fontDecoration.contains("b")) {
                f.setBold(true);
            }
            if (fontDecoration.contains("i")) {
                f.setItalic(true);
            }
            if (fontDecoration.contains("u")) {
                f.setUnderline(Font.U_SINGLE);
            }
        }
        if (fontColor != null && fontColor.isEmpty() == false) {
            short color = Short.parseShort(fontColor);
            f.setColor(color);
        }
        CellStyle style = workbook.createCellStyle();
        style.setFont(f);
        if (bgColor != null && bgColor.isEmpty() == false) {
            short color = Short.parseShort(bgColor);
            style.setFillForegroundColor(color);
            //style.setFillBackgroundColor(color);
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }
        if (textAlign != null && textAlign.isEmpty() == false) {
            if ("center".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.CENTER);
            } else if ("left".equalsIgnoreCase(textAlign)) {
                style.setAlignment(HorizontalAlignment.LEFT);
            } else if ("right".equals(textAlign)) {
                style.setAlignment(HorizontalAlignment.RIGHT);
            }
        }
        if (buttomBorder) {
            style.setBorderBottom(BorderStyle.MEDIUM);
            style.setBottomBorderColor((short) 9);
        }
        namedStyles.put(styleName, style);
    }
}

From source file:de.thb.ue.backend.util.EvaluationExcelFileGenerator.java

License:Apache License

private void configureCellStyles(Workbook wb) {
    commonStyle = wb.createCellStyle();//from   w ww .j  ava2  s .co m
    headerStyle = wb.createCellStyle();
    questionStyle = wb.createCellStyle();
    positiveStyle = wb.createCellStyle();
    positiveHeaderStyle = wb.createCellStyle();
    negativeStyle = wb.createCellStyle();
    negativeHeaderStyle = wb.createCellStyle();
    improvementStyle = wb.createCellStyle();
    improvementHeaderStyle = wb.createCellStyle();
    furtherStyle = wb.createCellStyle();
    furtherHeaderStyle = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBold(true);

    Font smallFont = wb.createFont();
    smallFont.setFontHeightInPoints((short) 8);

    commonStyle.setBorderBottom(CellStyle.BORDER_HAIR);
    commonStyle.setBorderTop(CellStyle.BORDER_HAIR);
    commonStyle.setBorderLeft(CellStyle.BORDER_HAIR);
    commonStyle.setBorderRight(CellStyle.BORDER_HAIR);
    commonStyle.setAlignment(CellStyle.ALIGN_CENTER);
    questionStyle.cloneStyleFrom(commonStyle);
    questionStyle.setFont(smallFont);
    questionStyle.setAlignment(CellStyle.ALIGN_LEFT);
    headerStyle.cloneStyleFrom(commonStyle);
    headerStyle.setFont(headerFont);

    positiveStyle.setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
    positiveStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        positiveStyle.setWrapText(true);

    negativeStyle.setFillForegroundColor(HSSFColor.ROSE.index);
    negativeStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        negativeStyle.setWrapText(true);

    improvementStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
    improvementStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        improvementStyle.setWrapText(true);

    furtherStyle.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index);
    furtherStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    //        furtherStyle.setWrapText(true);

    positiveHeaderStyle.cloneStyleFrom(positiveStyle);
    positiveHeaderStyle.setFont(headerFont);

    negativeHeaderStyle.cloneStyleFrom(negativeStyle);
    negativeHeaderStyle.setFont(headerFont);

    improvementHeaderStyle.cloneStyleFrom(improvementStyle);
    improvementHeaderStyle.setFont(headerFont);

    furtherHeaderStyle.cloneStyleFrom(furtherStyle);
    furtherHeaderStyle.setFont(headerFont);
}

From source file:excel.CellComments.java

License:Apache License

public static void main(String[] args) throws IOException {
    try (Workbook wb = new XSSFWorkbook()) {

        CreationHelper factory = wb.getCreationHelper();

        Sheet sheet = wb.createSheet();// w  w w  .  ja  v  a  2  s  .  c o m

        Cell cell1 = sheet.createRow(3).createCell(5);
        cell1.setCellValue("F4");

        Drawing<?> drawing = sheet.createDrawingPatriarch();

        ClientAnchor anchor = factory.createClientAnchor();

        Comment comment1 = drawing.createCellComment(anchor);
        RichTextString str1 = factory.createRichTextString("Hello, World!");
        comment1.setString(str1);
        comment1.setAuthor("Apache POI");
        cell1.setCellComment(comment1);

        Cell cell2 = sheet.createRow(2).createCell(2);
        cell2.setCellValue("C3");

        Comment comment2 = drawing.createCellComment(anchor);
        RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
        //apply custom font to the text in the comment
        Font font = wb.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 14);
        font.setBold(true);
        font.setColor(IndexedColors.RED.getIndex());
        str2.applyFont(font);

        comment2.setString(str2);
        comment2.setAuthor("Apache POI");
        comment2.setAddress(new CellAddress("C3"));

        try (FileOutputStream out = new FileOutputStream("comments.xlsx")) {
            wb.write(out);
        }
    }
}

From source file:fi.thl.pivot.export.XlsxExporter.java

private Font createValueFont(Workbook wb) {
    Font valueFont = wb.createFont();
    valueFont.setBold(false);
    valueFont.setFontName(FONT_FAMILY);/*  w w w .j  a v  a2  s . c om*/
    valueFont.setFontHeightInPoints(FONT_SIZE);
    return valueFont;
}

From source file:fi.thl.pivot.export.XlsxExporter.java

private Font createHeaderFont(Workbook wb) {
    Font headerFont = wb.createFont();
    headerFont.setBold(true);
    headerFont.setFontName(FONT_FAMILY);
    headerFont.setFontHeightInPoints(FONT_SIZE);
    return headerFont;
}

From source file:guru.qas.martini.report.DefaultState.java

License:Apache License

public void updateLongestExecutions() {
    if (!longestExecutionCells.isEmpty()) {
        for (Cell cell : longestExecutionCells) {
            CellStyle original = cell.getCellStyle();
            Sheet sheet = cell.getSheet();
            Workbook workbook = sheet.getWorkbook();
            CellStyle newStyle = workbook.createCellStyle();
            newStyle.cloneStyleFrom(original);
            int originalFontIndex = original.getFontIndexAsInt();
            Font originalFont = workbook.getFontAt(originalFontIndex);

            Font font = workbook.createFont();
            font.setBold(true);
            font.setColor(IndexedColors.DARK_RED.getIndex());
            font.setFontHeight((short) Math.round(originalFont.getFontHeight() * 1.5));
            newStyle.setFont(font);// ww  w . j  a v  a 2s .  c o m
            cell.setCellStyle(newStyle);

            Row row = cell.getRow();
            short firstCellNum = row.getFirstCellNum();
            short lastCellNum = row.getLastCellNum();

            for (int i = firstCellNum; i < lastCellNum; i++) {
                Cell rowCell = row.getCell(i);
                original = rowCell.getCellStyle();
                CellStyle borderStyle = workbook.createCellStyle();
                borderStyle.cloneStyleFrom(original);
                borderStyle.setBorderTop(BorderStyle.MEDIUM);
                borderStyle.setBorderBottom(BorderStyle.MEDIUM);

                if (i == cell.getColumnIndex()) {
                    borderStyle.setBorderLeft(BorderStyle.MEDIUM);
                    borderStyle.setBorderRight(BorderStyle.MEDIUM);
                } else if (i == firstCellNum) {
                    borderStyle.setBorderLeft(BorderStyle.MEDIUM);
                } else if (i == lastCellNum - 1) {
                    borderStyle.setBorderRight(BorderStyle.MEDIUM);
                }
                rowCell.setCellStyle(borderStyle);
            }
        }
    }
}

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 ww.  ja v a  2s.co  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);
            }
        }
    }
}