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:ro.dabuno.office.integration.BusinessPlan.java

License:Apache License

/**
 * create a library of cell styles/*  w  w w .  jav a2 s.  c  o  m*/
 */
private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    DataFormat df = wb.createDataFormat();

    CellStyle style;
    Font headerFont = wb.createFont();
    headerFont.setBold(true);
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(headerFont);
    styles.put("header", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(headerFont);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("header_date", style);

    Font font1 = wb.createFont();
    font1.setBold(true);
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setFont(font1);
    styles.put("cell_b", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFont(font1);
    styles.put("cell_b_centered", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(font1);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("cell_b_date", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(font1);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("cell_g", style);

    Font font2 = wb.createFont();
    font2.setColor(IndexedColors.BLUE.getIndex());
    font2.setBold(true);
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setFont(font2);
    styles.put("cell_bb", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(font1);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("cell_bg", style);

    Font font3 = wb.createFont();
    font3.setFontHeightInPoints((short) 14);
    font3.setColor(IndexedColors.DARK_BLUE.getIndex());
    font3.setBold(true);
    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setFont(font3);
    style.setWrapText(true);
    styles.put("cell_h", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setWrapText(true);
    styles.put("cell_normal", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setWrapText(true);
    styles.put("cell_normal_centered", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setWrapText(true);
    style.setDataFormat(df.getFormat("d-mmm"));
    styles.put("cell_normal_date", style);

    style = createBorderedStyle(wb);
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setIndention((short) 1);
    style.setWrapText(true);
    styles.put("cell_indented", style);

    style = createBorderedStyle(wb);
    style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("cell_blue", style);

    return styles;
}

From source file:rpt.GUI.ProgramStrategist.CyclePlans.CompareDialogController.java

public void okButtonClicked() throws IOException {
    // create two new maps, one for currentCycleplan and one for the comparison plan
    Map<String, TableVariant> currentCyclePlan = new HashMap<String, TableVariant>();
    Map<String, TableVariant> oldCyclePlan = new HashMap<String, TableVariant>();
    Map<String, TableVariant> movedVariants = new HashMap<String, TableVariant>();
    Map<String, TableVariant> changedVariants = new HashMap<String, TableVariant>();
    Map<String, Map<String, String>> changedInfo = new HashMap<String, Map<String, String>>();
    Map<String, String> diffValues = new HashMap<String, String>();

    Statement statement;//from w  w w  . j  av a  2  s  .com
    try {
        // Set current YYwWW and use to ignore variants that are no longer in production
        Calendar cal = Calendar.getInstance();
        String currentWeek = cal.get(Calendar.YEAR) % 100 + "w" + cal.get(Calendar.WEEK_OF_YEAR);

        // Extract all variants in the current cycleplan and put them in an map
        System.out.println("Extracting current variants");
        statement = RPT.conn.createStatement();
        statement.setQueryTimeout(30);
        String query = "SELECT * FROM VARIANTS, VariantBelongsToCyclePlan WHERE "
                + "VariantBelongsToCyclePlan.CyclePlanID= \'" + CyclePlansController.selectedCyclePlan + "\' "
                + "AND VARIANTS.VariantID = VariantBelongsToCyclePlan.VariantID " + "AND EndOfProd > '"
                + currentWeek + "'";
        ResultSet rs = statement.executeQuery(query);

        while (rs.next()) {
            TableVariant entry = new TableVariant(rs.getString("Plant"), rs.getString("Platform"),
                    rs.getString("Vehicle"), rs.getString("Propulsion"), rs.getString("Denomination"),
                    rs.getString("Fuel"), rs.getString("EngineFamily"), rs.getString("Generation"),
                    "EngineName not used", rs.getString("EngineCode"), rs.getString("Displacement"),
                    rs.getString("EnginePower"), rs.getString("ElMotorPower"), rs.getString("Torque"),
                    rs.getString("TorqueOverBoost"), rs.getString("GearboxType"), rs.getString("Gears"),
                    rs.getString("Gearbox"), rs.getString("Driveline"), rs.getString("TransmissionCode"),
                    rs.getString("CertGroup"), rs.getString("EmissionClass"), rs.getString("StartOfProd"),
                    rs.getString("EndOfProd"));
            currentCyclePlan.put(entry.getVariantID(), entry);
        }
        //Now extract all variants in the cycleplan to compare with
        System.out.println("Extracting comparison variants");
        query = "SELECT * FROM VARIANTS, VariantBelongsToCyclePlan WHERE "
                + "VariantBelongsToCyclePlan.CyclePlanID= \'"
                + cyclePlanSelector.getSelectionModel().getSelectedItem().toString() + "\' "
                + "AND VARIANTS.VariantID = VariantBelongsToCyclePlan.VariantID " + "AND EndOfProd > '"
                + currentWeek + "'";
        rs = statement.executeQuery(query);

        while (rs.next()) {
            TableVariant entry = new TableVariant(rs.getString("Plant"), rs.getString("Platform"),
                    rs.getString("Vehicle"), rs.getString("Propulsion"), rs.getString("Denomination"),
                    rs.getString("Fuel"), rs.getString("EngineFamily"), rs.getString("Generation"),
                    "EngineName not used", rs.getString("EngineCode"), rs.getString("Displacement"),
                    rs.getString("EnginePower"), rs.getString("ElMotorPower"), rs.getString("Torque"),
                    rs.getString("TorqueOverBoost"), rs.getString("GearboxType"), rs.getString("Gears"),
                    rs.getString("Gearbox"), rs.getString("Driveline"), rs.getString("TransmissionCode"),
                    rs.getString("CertGroup"), rs.getString("EmissionClass"), rs.getString("StartOfProd"),
                    rs.getString("EndOfProd"));
            oldCyclePlan.put(entry.getVariantID(), entry);
        }

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    //for each variant in current plan, remove from both if it exists in old
    for (Iterator<Map.Entry<String, TableVariant>> entries = currentCyclePlan.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        if (oldCyclePlan.containsKey(entry.getKey())) {
            entries.remove(); // remove from currentCyclePlan
            oldCyclePlan.remove(entry.getKey());
        }
    }

    // Now need to check if some entries were only moved in time
    for (Iterator<Map.Entry<String, TableVariant>> entries = currentCyclePlan.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        try {
            statement = RPT.conn.createStatement();
            statement.setQueryTimeout(30);
            //TODO
            //Add all columns except Start of production, as all will be important to find it correctly
            String query = "SELECT VARIANTS.VariantID, VARIANTS.StartOfProd, VARIANTS.EndOfProd FROM VARIANTS, VariantBelongsToCyclePlan WHERE "
                    + "VARIANTS.VariantID = VariantBelongsToCyclePlan.VariantID AND "
                    + "VariantBelongsToCyclePlan.CyclePlanID= \'"
                    + cyclePlanSelector.getSelectionModel().getSelectedItem().toString() + "\' AND "
                    + "VARIANTS.Plant = \'" + entry.getValue().getPlant() + "\' AND " + "VARIANTS.Platform = \'"
                    + entry.getValue().getPlatform() + "\' AND " + "VARIANTS.Vehicle = \'"
                    + entry.getValue().getVehicle() + "\' AND " + "VARIANTS.Propulsion = \'"
                    + entry.getValue().getPropulsion() + "\' AND " + "VARIANTS.Denomination = \'"
                    + entry.getValue().getDenomination() + "\' AND " + "VARIANTS.Fuel = \'"
                    + entry.getValue().getFuel() + "\' AND " + "VARIANTS.EngineFamily = \'"
                    + entry.getValue().getEngineFamily() + "\' AND " + "VARIANTS.Generation = \'"
                    + entry.getValue().getGeneration() + "\' AND " + "VARIANTS.EngineCode = \'"
                    + entry.getValue().getEngineCode() + "\' AND " + "VARIANTS.Displacement = \'"
                    + entry.getValue().getDisplacement() + "\' AND " + "VARIANTS.EnginePower = \'"
                    + entry.getValue().getEnginePower() + "\' AND " + "VARIANTS.ElMotorPower = \'"
                    + entry.getValue().getElMotorPower() + "\' AND " + "VARIANTS.TorqueOverBoost = \'"
                    + entry.getValue().getTorqueOverBoost() + "\' AND " + "VARIANTS.GearboxType = \'"
                    + entry.getValue().getGearboxType() + "\' AND " + "VARIANTS.Gears = \'"
                    + entry.getValue().getGears() + "\' AND " + "VARIANTS.Gearbox = \'"
                    + entry.getValue().getGearbox() + "\' AND " + "VARIANTS.Driveline = \'"
                    + entry.getValue().getDriveline() + "\' AND " + "VARIANTS.TransmissionCode = \'"
                    + entry.getValue().getTransmissionCode() + "\' AND " + "VARIANTS.CertGroup = \'"
                    + entry.getValue().getCertGroup() + "\' AND " // may remove once
                    + "VARIANTS.EmissionClass = \'" + entry.getValue().getEmissionClass() + "\'";
            ResultSet rs = statement.executeQuery(query);
            if (rs.next()) {
                entry.getValue().setOldSOP(rs.getString("StartOfProd"));
                entry.getValue().setOldEOP(rs.getString("EndOfProd"));
                movedVariants.put(entry.getKey(), entry.getValue()); //Save variant to moved map
                entries.remove(); //remove variant from current map
                oldCyclePlan.remove(rs.getString("VariantID")); //remove variant from old map
            }

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    // Now check for variants that have been slightly changed only.
    // Show a dialog window allowing the user to define what a minor change is
    majorChanges = new ArrayList();
    Stage stage;
    Parent root;
    stage = new Stage();
    root = FXMLLoader
            .load(getClass().getResource("/rpt/GUI/ProgramStrategist/CyclePlans/dialogDefineChanged.fxml"));
    stage.setScene(new Scene(root));
    stage.setTitle("Set change definition");
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.showAndWait(); // pause until the user has selected minor changes

    // Now loop through the remaining Added items and check if they are to be moved to "Modified"
    //for (String s : majorChanges) {
    //    System.out.println(s);
    //}
    // Create string for extracting data which has been judged as minor
    //String dataString = ""; // Data which will be used for difference check
    //for (String s : majorChanges) {
    //    dataString = dataString + ", VARIANTS." + s;
    //}
    // Build list of parameters to extract and compare with the new variant
    ArrayList<String> infoArray = new ArrayList();
    String query = "PRAGMA table_info(VARIANTS)"; //Get all column names
    String extractionData = "";
    try {
        statement = RPT.conn.createStatement();
        statement.setQueryTimeout(30);
        ResultSet rsColumns = statement.executeQuery(query);
        //traverser through list of columns and add those not pointed out as MAJOR
        boolean first = true;
        while (rsColumns.next()) {
            if (!(majorChanges.contains(rsColumns.getString("name")))) {
                infoArray.add(rsColumns.getString("name"));
                if (first) {
                    extractionData = extractionData + "VARIANTS." + rsColumns.getString("name");
                    first = false;
                } else {
                    extractionData = extractionData + ", VARIANTS." + rsColumns.getString("name");
                }
            }
        }

    } catch (Exception e) {
        System.err.println("CompareDialogController error when building extraction data: " + e.getMessage());
    }

    for (Iterator<Map.Entry<String, TableVariant>> entries = currentCyclePlan.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        try {
            statement = RPT.conn.createStatement();
            statement.setQueryTimeout(30);
            query = "SELECT ";
            query = query + extractionData;
            query = query + " FROM VARIANTS, VariantBelongsToCyclePlan WHERE "
                    + "VARIANTS.VariantID = VariantBelongsToCyclePlan.VariantID AND "
                    + "VariantBelongsToCyclePlan.CyclePlanID= \'"
                    + cyclePlanSelector.getSelectionModel().getSelectedItem().toString() + "\'";

            for (String s : majorChanges) {
                query = query + " AND VARIANTS." + s + " = \'" + entry.getValue().getValue(s) + "\'";
            }
            //System.out.println(query);
            ResultSet rs = statement.executeQuery(query);
            if (rs.next()) {
                // Found "similar enough"
                changedVariants.put(entry.getKey(), entry.getValue()); //Save variant to moved map
                entries.remove(); //remove variant from current map
                oldCyclePlan.remove(rs.getString("VariantID")); //remove variant from old map

                // now loop through all non major columns and check for difference between variant in new and old cycle plan
                diffValues = new HashMap<String, String>();
                for (String s : infoArray) {
                    if (!rs.getString(s).equals(entry.getValue().getValue(s))) {
                        diffValues.put(s, rs.getString(s));
                    }
                }

                changedInfo.put(entry.getKey(), diffValues); //Add information about differences between new and old variant
            }

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    // Open file selector and let user specify report file
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Information");

    //turn off gridlines
    sheet.setDisplayGridlines(false);
    sheet.setPrintGridlines(false);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);
    PrintSetup printSetup = sheet.getPrintSetup();

    //the following three statements are required only for HSSF
    sheet.setAutobreaks(true);
    printSetup.setFitHeight((short) 1);
    printSetup.setFitWidth((short) 1);

    // print out information about baseline cycle plan
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    Font headerFont = workbook.createFont();
    headerFont.setBold(true);
    CellStyle style = workbook.createCellStyle();
    style.setFont(headerFont);
    cell.setCellStyle(style);
    cell.setCellValue("Cycle plan:");
    cell = row.createCell(1);
    cell.setCellValue(CyclePlansController.selectedCyclePlan);

    // print out information about comaparison cycle plan
    row = sheet.createRow(1);
    cell = row.createCell(0);
    headerFont = workbook.createFont();
    headerFont.setBold(true);
    style.setFont(headerFont);
    cell.setCellStyle(style);
    cell.setCellValue("Compared to:");
    cell = row.createCell(1);
    cell.setCellValue(cyclePlanSelector.getSelectionModel().getSelectedItem().toString());

    sheet.autoSizeColumn(0);
    sheet.autoSizeColumn(1);

    // Write Added variant information
    sheet = workbook.createSheet("Added");
    //freeze the first row
    sheet.createFreezePane(0, 1);
    row = sheet.createRow(0);
    writeHeaders(workbook, row, false);
    int rowNum = 1;
    int amountOfColumns = 0;
    // loop through added
    for (Iterator<Map.Entry<String, TableVariant>> entries = currentCyclePlan.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        row = sheet.createRow(rowNum);
        amountOfColumns = writeRow(workbook, sheet, row, entry.getValue(), null, false, false);

        rowNum++;
    }
    //autosize all columns
    for (int i = 0; i < amountOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    amountOfColumns = 0;

    // Write Removed variant information
    sheet = workbook.createSheet("Removed");
    //freeze the first row
    sheet.createFreezePane(0, 1);
    row = sheet.createRow(0);
    writeHeaders(workbook, row, false);
    rowNum = 1;
    // loop through removed
    for (Iterator<Map.Entry<String, TableVariant>> entries = oldCyclePlan.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        row = sheet.createRow(rowNum);
        amountOfColumns = writeRow(workbook, sheet, row, entry.getValue(), null, false, false);

        rowNum++;
    }
    //autosize all columns
    for (int i = 0; i < amountOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    amountOfColumns = 0;

    // Write Changed variant information
    sheet = workbook.createSheet("Changed");
    //freeze the first row
    sheet.createFreezePane(0, 1);
    row = sheet.createRow(0);
    writeHeaders(workbook, row, false);
    rowNum = 1;
    // loop through changed
    for (Iterator<Map.Entry<String, TableVariant>> entries = changedVariants.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        row = sheet.createRow(rowNum);
        amountOfColumns = writeRow(workbook, sheet, row, entry.getValue(), changedInfo, true, false);

        rowNum++;
    }
    //autosize all columns
    for (int i = 0; i < amountOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    amountOfColumns = 0;

    // Write Moved variant information
    sheet = workbook.createSheet("Moved");
    //freeze the first row
    sheet.createFreezePane(0, 1);
    row = sheet.createRow(0);
    writeHeaders(workbook, row, true);
    rowNum = 1;
    for (Iterator<Map.Entry<String, TableVariant>> entries = movedVariants.entrySet().iterator(); entries
            .hasNext();) {
        Map.Entry<String, TableVariant> entry = entries.next();
        row = sheet.createRow(rowNum);
        amountOfColumns = writeRow(workbook, sheet, row, entry.getValue(), null, false, true);

        rowNum++;

    }
    //autosize all columns
    for (int i = 0; i < amountOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    amountOfColumns = 0;

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save Comparison Result File");

    File selectedFile = fileChooser.showSaveDialog(null);

    if (selectedFile != null) {
        try {
            FileOutputStream out = new FileOutputStream(selectedFile);
            workbook.write(out);
            out.close();
            System.out.println("Excel written successfully..");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    closeDialog();
}

From source file:rpt.GUI.ProgramStrategist.CyclePlans.CompareDialogController.java

private void writeHeaders(Workbook wb, Row row, Boolean addOldSOP) {
    Cell cell = row.createCell(0);/*from   www.j  ava  2 s.  c o  m*/
    XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
    Font headerFont = wb.createFont();
    headerFont.setBold(true);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(220, 220, 220)));
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(headerFont);

    cell.setCellStyle(style);
    cell.setCellValue("Plant");

    cell = row.createCell(1);
    cell.setCellStyle(style);
    cell.setCellValue("Platform");

    cell = row.createCell(2);
    cell.setCellStyle(style);
    cell.setCellValue("Vehicle");

    cell = row.createCell(3);
    cell.setCellStyle(style);
    cell.setCellValue("Propulsion");

    cell = row.createCell(4);
    cell.setCellStyle(style);
    cell.setCellValue("Denomination");

    cell = row.createCell(5);
    cell.setCellStyle(style);
    cell.setCellValue("Fuel");

    cell = row.createCell(6);
    cell.setCellStyle(style);
    cell.setCellValue("Engine Family");

    cell = row.createCell(7);
    cell.setCellStyle(style);
    cell.setCellValue("Generation");

    cell = row.createCell(8);
    cell.setCellStyle(style);
    cell.setCellValue("Engine Code");

    cell = row.createCell(9);
    cell.setCellStyle(style);
    cell.setCellValue("Displacement");

    cell = row.createCell(10);
    cell.setCellStyle(style);
    cell.setCellValue("Engine power (PS)");

    cell = row.createCell(11);
    cell.setCellStyle(style);
    cell.setCellValue("Electric motor power (PS)");

    cell = row.createCell(12);
    cell.setCellStyle(style);
    cell.setCellValue("Torque");

    cell = row.createCell(13);
    cell.setCellStyle(style);
    cell.setCellValue("Torque overboost");

    cell = row.createCell(14);
    cell.setCellStyle(style);
    cell.setCellValue("Gearbox Type");

    cell = row.createCell(15);
    cell.setCellStyle(style);
    cell.setCellValue("Gears");

    cell = row.createCell(16);
    cell.setCellStyle(style);
    cell.setCellValue("Gearbox");

    cell = row.createCell(17);
    cell.setCellStyle(style);
    cell.setCellValue("Driveline");

    cell = row.createCell(18);
    cell.setCellStyle(style);
    cell.setCellValue("Transmission Code");

    cell = row.createCell(19);
    cell.setCellStyle(style);
    cell.setCellValue("Cert Group");

    cell = row.createCell(20);
    cell.setCellStyle(style);
    cell.setCellValue("Emission Class");

    cell = row.createCell(21);
    cell.setCellStyle(style);
    cell.setCellValue("SOP");

    cell = row.createCell(22);
    cell.setCellStyle(style);
    cell.setCellValue("EOP");

    if (addOldSOP) {
        cell = row.createCell(23);
        cell.setCellStyle(style);
        cell.setCellValue("Old SOP");
    }

    if (addOldSOP) { //Same boolean flag
        cell = row.createCell(24);
        cell.setCellStyle(style);
        cell.setCellValue("Old EOP");
    }
}

From source file:ru.runa.common.web.action.AbstractExportExcelAction.java

License:Open Source License

private void buildHeader(HttpServletRequest request, HSSFWorkbook workbook,
        BatchPresentation batchPresentation) {
    CellStyle boldCellStyle = workbook.createCellStyle();
    Font boldFont = workbook.createFont();
    boldFont.setBold(true);
    boldCellStyle.setFont(boldFont);/*  ww  w . jav a  2s . co m*/
    Row header = workbook.getSheetAt(0).createRow(0);
    int i = 0;
    for (FieldDescriptor fieldDescriptor : batchPresentation.getDisplayFields()) {
        if (fieldDescriptor.displayName.startsWith(ClassPresentation.editable_prefix)
                || fieldDescriptor.displayName.startsWith(ClassPresentation.filterable_prefix)
                || fieldDescriptor.fieldState != FieldState.ENABLED) {
            continue;
        }
        Cell cell = header.createCell(i++);
        cell.setCellStyle(boldCellStyle);
        cell.setCellValue(getDisplayString(request, fieldDescriptor));
    }
}

From source file:se.mithlond.services.content.impl.ejb.report.ExcelReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww  w .  j a v  a 2 s  .c om*/
 */
@Override
@SuppressWarnings("all")
public CellStyle getCellStyle(final ExcelElement el, final Workbook workbook) {

    // Check sanity
    Validate.notNull(workbook, "workbook");
    Validate.notNull(el, "el");

    // Acquire the el and Font as expected
    final CellStyle toReturn = workbook.createCellStyle();
    final Font theFont = workbook.createFont();

    switch (el) {

    case TITLE:
        theFont.setFontHeightInPoints((short) 18);
        theFont.setBold(true);
        theFont.setColor(IndexedColors.BLUE_GREY.getIndex());

        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        break;

    case HEADER:
        theFont.setFontHeightInPoints((short) 11);
        theFont.setColor(IndexedColors.WHITE.getIndex());

        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex());
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setWrapText(true);
        break;

    case CELL:

        toReturn.setAlignment(HorizontalAlignment.LEFT);
        toReturn.setWrapText(true);
        toReturn.setBorderRight(BORDER_THIN);
        toReturn.setRightBorderColor(GREY_25_PERCENT);
        toReturn.setBorderLeft(BORDER_THIN);
        toReturn.setLeftBorderColor(GREY_25_PERCENT);
        toReturn.setBorderTop(BORDER_THIN);
        toReturn.setTopBorderColor(GREY_25_PERCENT);
        toReturn.setBorderBottom(BORDER_THIN);
        toReturn.setBottomBorderColor(GREY_25_PERCENT);
        break;

    case NON_WRAPPING:
        toReturn.setAlignment(HorizontalAlignment.LEFT);
        toReturn.setWrapText(false);
        toReturn.setBorderRight(BORDER_THIN);
        toReturn.setRightBorderColor(GREY_25_PERCENT);
        toReturn.setBorderLeft(BORDER_THIN);
        toReturn.setLeftBorderColor(GREY_25_PERCENT);
        toReturn.setBorderTop(BORDER_THIN);
        toReturn.setTopBorderColor(GREY_25_PERCENT);
        toReturn.setBorderBottom(BORDER_THIN);
        toReturn.setBottomBorderColor(GREY_25_PERCENT);
        break;

    case FORMULA:
        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(GREY_25_PERCENT);
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setDataFormat(workbook.createDataFormat().getFormat("0.00"));
        break;

    case ALT_FORMULA:
        toReturn.setAlignment(HorizontalAlignment.CENTER);
        toReturn.setVerticalAlignment(VerticalAlignment.CENTER);
        toReturn.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
        toReturn.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        toReturn.setDataFormat(workbook.createDataFormat().getFormat("0.00"));
        break;

    default:
        throw new IllegalArgumentException(
                "Style [" + el.name() + "] was not defined. " + "Blame the programmer.");
    }

    // All done.
    toReturn.setFont(theFont);
    return toReturn;
}

From source file:stroom.dashboard.server.download.ExcelTarget.java

License:Apache License

@Override
public void writeHeading(final Field field, final String heading) throws IOException {
    // Create a style for headings.
    final Font headingFont = wb.createFont();
    headingFont.setBold(true);
    final CellStyle headingStyle = wb.createCellStyle();
    headingStyle.setFont(headingFont);//from ww  w  .  j a v a 2s.  co m

    final Cell cell = row.createCell(colNum++);
    cell.setCellType(Cell.CELL_TYPE_STRING);
    cell.setCellValue(heading);
    cell.setCellStyle(headingStyle);
}