Example usage for org.apache.poi.ss.usermodel CellStyle setBorderLeft

List of usage examples for org.apache.poi.ss.usermodel CellStyle setBorderLeft

Introduction

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

Prototype

void setBorderLeft(BorderStyle border);

Source Link

Document

set the type of border to use for the left border of the cell

Usage

From source file:it.eng.spagobi.engines.qbe.exporter.QbeXLSExporter.java

License:Mozilla Public License

public CellStyle buildCellStyle(Sheet sheet) {

    CellStyle cellStyle = sheet.getWorkbook().createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);

    String cellBGColor = (String) this.getProperty(PROPERTY_CELL_BACKGROUND_COLOR);
    logger.debug("Cell background color : " + cellBGColor);
    short backgroundColorIndex = cellBGColor != null ? IndexedColors.valueOf(cellBGColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BACKGROUND_COLOR).getIndex();
    cellStyle.setFillForegroundColor(backgroundColorIndex);

    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);

    String bordeBorderColor = (String) this.getProperty(PROPERTY_CELL_BORDER_COLOR);
    logger.debug("Cell border color : " + bordeBorderColor);
    short borderColorIndex = bordeBorderColor != null ? IndexedColors.valueOf(bordeBorderColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_BORDER_COLOR).getIndex();

    cellStyle.setLeftBorderColor(borderColorIndex);
    cellStyle.setRightBorderColor(borderColorIndex);
    cellStyle.setBottomBorderColor(borderColorIndex);
    cellStyle.setTopBorderColor(borderColorIndex);

    Font font = sheet.getWorkbook().createFont();

    Short cellFontSize = (Short) this.getProperty(PROPERTY_CELL_FONT_SIZE);
    logger.debug("Cell font size : " + cellFontSize);
    short cellFontSizeShort = cellFontSize != null ? cellFontSize.shortValue() : DEFAULT_CELL_FONT_SIZE;
    font.setFontHeightInPoints(cellFontSizeShort);

    String fontName = (String) this.getProperty(PROPERTY_FONT_NAME);
    logger.debug("Font name : " + fontName);
    fontName = fontName != null ? fontName : DEFAULT_FONT_NAME;
    font.setFontName(fontName);//from   w  w w.  j  ava 2s  .com

    String cellColor = (String) this.getProperty(PROPERTY_CELL_COLOR);
    logger.debug("Cell color : " + cellColor);
    short cellColorIndex = cellColor != null ? IndexedColors.valueOf(cellColor).getIndex()
            : IndexedColors.valueOf(DEFAULT_CELL_COLOR).getIndex();
    font.setColor(cellColorIndex);

    cellStyle.setFont(font);
    return cellStyle;
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

protected CellStyle createStyle(jdbreport.model.CellStyle style, Workbook wb) {

    CellStyle newStyle = wb.createCellStyle();
    newStyle.setAlignment(convertHorizontalAlign(style.getHorizontalAlignment()));
    newStyle.setVerticalAlignment(convertVerticalAlign(style.getVerticalAlignment()));

    Border border = style.getBorders(Border.LINE_BOTTOM);
    if (border != null) {
        newStyle.setBorderBottom(getBorder(border));
        newStyle.setBottomBorderColor(colorToIndex(wb, border.getColor()));
    }//ww w  .j a  v  a  2 s  . c  o  m
    border = style.getBorders(Border.LINE_TOP);
    if (border != null) {
        newStyle.setBorderTop(getBorder(border));
        newStyle.setTopBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_LEFT);
    if (border != null) {
        newStyle.setBorderLeft(getBorder(border));
        newStyle.setLeftBorderColor(colorToIndex(wb, border.getColor()));
    }
    border = style.getBorders(Border.LINE_RIGHT);
    if (border != null) {
        newStyle.setBorderRight(getBorder(border));
        newStyle.setRightBorderColor(colorToIndex(wb, border.getColor()));
    }

    Font font = wb.createFont();
    font.setFontName(style.getFamily());
    if (style.isBold()) {
        font.setBold(true);
    }
    font.setItalic(style.isItalic());
    if (style.isUnderline()) {
        font.setUnderline(Font.U_SINGLE);
    }
    if (style.isStrikethrough()) {
        font.setStrikeout(true);
    }
    font.setFontHeightInPoints((short) style.getSize());
    if (style.getForegroundColor() != null && !style.getForegroundColor().equals(Color.black)) {
        font.setColor(colorToIndex(wb, style.getForegroundColor()));
    }

    newStyle.setFont(font);

    if (style.getBackground() != null && !style.getBackground().equals(Color.white)) {
        short colorIndex = colorToIndex(wb, style.getBackground());
        newStyle.setFillForegroundColor(colorIndex);
        newStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    }

    if (style.getAngle() != 0) {
        int angle = style.getAngle();
        if (angle > 90 && angle <= 180) {
            angle = 90;
        } else if (angle > 180 && angle <= 270) {
            angle = -90;
        } else if (angle > 270) {
            angle = -(360 - angle);
        }
        newStyle.setRotation((short) angle);
    }

    newStyle.setWrapText(style.isWrapLine());

    return newStyle;
}

From source file:jgnash.convert.exportantur.ssf.AccountExport.java

License:Open Source License

public static void exportAccount(final Account account, final String[] columnNames, final LocalDate startDate,
        final LocalDate endDate, final File file) {
    Objects.requireNonNull(account);
    Objects.requireNonNull(startDate);
    Objects.requireNonNull(endDate);
    Objects.requireNonNull(file);
    Objects.requireNonNull(columnNames);

    final String extension = FileUtils.getFileExtension(file.getAbsolutePath());

    try (final Workbook wb = extension.equals("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook()) {
        final CreationHelper createHelper = wb.getCreationHelper();

        // create a new sheet
        final Sheet s = wb.createSheet(account.getName());

        // create 2 fonts objects
        final Font defaultFont = wb.createFont();
        final Font headerFont = wb.createFont();

        defaultFont.setFontHeightInPoints((short) 10);
        defaultFont.setColor(IndexedColors.BLACK.getIndex());

        headerFont.setFontHeightInPoints((short) 11);
        headerFont.setColor(IndexedColors.BLACK.getIndex());
        headerFont.setBold(true);/*from w  w w .ja  va 2s.  co m*/

        // create header cell styles
        final CellStyle headerStyle = wb.createCellStyle();

        // Set the other cell style and formatting
        headerStyle.setBorderBottom(BorderStyle.THIN);
        headerStyle.setBorderTop(BorderStyle.THIN);
        headerStyle.setBorderLeft(BorderStyle.THIN);
        headerStyle.setBorderRight(BorderStyle.THIN);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        DataFormat df_header = wb.createDataFormat();

        headerStyle.setDataFormat(df_header.getFormat("text"));
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER);

        final CellStyle dateStyle = wb.createCellStyle();
        dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("mm/dd/yy"));
        dateStyle.setFont(defaultFont);

        final CellStyle timestampStyle = wb.createCellStyle();
        timestampStyle.setDataFormat(createHelper.createDataFormat().getFormat("YYYY-MM-DD HH:MM:SS"));
        timestampStyle.setFont(defaultFont);

        final CellStyle textStyle = wb.createCellStyle();
        textStyle.setFont(defaultFont);

        final CellStyle amountStyle = wb.createCellStyle();
        amountStyle.setFont(defaultFont);
        amountStyle.setAlignment(HorizontalAlignment.RIGHT);

        final DecimalFormat format = (DecimalFormat) NumericFormats
                .getFullCommodityFormat(account.getCurrencyNode());
        final String pattern = format.toLocalizedPattern().replace("", account.getCurrencyNode().getPrefix());
        final DataFormat df = wb.createDataFormat();
        amountStyle.setDataFormat(df.getFormat(pattern));

        // Create headers
        int row = 0;
        Row r = s.createRow(row);
        for (int i = 0; i < columnNames.length; i++) {
            Cell c = r.createCell(i);
            c.setCellValue(createHelper.createRichTextString(columnNames[i]));
            c.setCellStyle(headerStyle);
        }

        // Dump the transactions
        for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
            r = s.createRow(++row);

            int col = 0;

            // date
            Cell c = r.createCell(col, CellType.STRING);
            c.setCellValue(DateUtils.asDate(transaction.getLocalDate()));
            c.setCellStyle(dateStyle);

            // timestamp
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(DateUtils.asDate(transaction.getTimestamp()));
            c.setCellStyle(timestampStyle);

            // number
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getNumber());
            c.setCellStyle(textStyle);

            // payee
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getPayee());
            c.setCellStyle(textStyle);

            // memo
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getMemo());
            c.setCellStyle(textStyle);

            // account
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(getAccountColumnValue(transaction, account));
            c.setCellStyle(textStyle);

            // clr, strip any zero width spaces
            c = r.createCell(++col, CellType.STRING);
            c.setCellValue(transaction.getReconciled(account).toString().replaceAll(ZERO_WIDTH_SPACE, ""));
            c.setCellStyle(textStyle);

            final BigDecimal amount = transaction.getAmount(account);

            // increase
            c = r.createCell(++col, CellType.NUMERIC);
            if (amount.signum() >= 0) {
                c.setCellValue(amount.doubleValue());
            }
            c.setCellStyle(amountStyle);

            // decrease
            c = r.createCell(++col, CellType.NUMERIC);
            if (amount.signum() < 0) {
                c.setCellValue(amount.abs().doubleValue());
            }
            c.setCellStyle(amountStyle);

            // balance
            c = r.createCell(++col, CellType.NUMERIC);
            c.setCellValue(account.getBalanceAt(transaction).doubleValue());
            c.setCellStyle(amountStyle);
        }

        // autosize the column widths
        final short columnCount = s.getRow(1).getLastCellNum();

        // autosize all of the columns + 10 pixels
        for (int i = 0; i <= columnCount; i++) {
            s.autoSizeColumn(i);
            s.setColumnWidth(i, s.getColumnWidth(i) + 10);
        }

        Logger.getLogger(AccountExport.class.getName()).log(Level.INFO, "{0} cell styles were used",
                wb.getNumCellStyles());

        // Save
        final String filename;

        if (wb instanceof XSSFWorkbook) {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xlsx";
        } else {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xls";
        }

        try (final OutputStream out = Files.newOutputStream(Paths.get(filename))) {
            wb.write(out);
        } catch (final Exception e) {
            Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
        }

    } catch (final IOException e) {
        Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}

From source file:jgnash.convert.exports.ssf.AccountExport.java

License:Open Source License

public static void exportAccount(final Account account, final String[] columnNames, final LocalDate startDate,
        final LocalDate endDate, final File file) {
    Objects.requireNonNull(account);
    Objects.requireNonNull(startDate);
    Objects.requireNonNull(endDate);
    Objects.requireNonNull(file);
    Objects.requireNonNull(columnNames);

    final String extension = FileUtils.getFileExtension(file.getAbsolutePath());

    try (final Workbook wb = extension.equals("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook()) {
        final CreationHelper createHelper = wb.getCreationHelper();

        // create a new sheet
        final Sheet s = wb.createSheet(account.getName());

        // create 2 fonts objects
        final Font defaultFont = wb.createFont();
        final Font headerFont = wb.createFont();

        defaultFont.setFontHeightInPoints((short) 10);
        defaultFont.setColor(IndexedColors.BLACK.getIndex());

        headerFont.setFontHeightInPoints((short) 11);
        headerFont.setColor(IndexedColors.BLACK.getIndex());
        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

        // create header cell styles
        final CellStyle headerStyle = wb.createCellStyle();

        // Set the other cell style and formatting
        headerStyle.setBorderBottom(CellStyle.BORDER_THIN);
        headerStyle.setBorderTop(CellStyle.BORDER_THIN);
        headerStyle.setBorderLeft(CellStyle.BORDER_THIN);
        headerStyle.setBorderRight(CellStyle.BORDER_THIN);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

        DataFormat df_header = wb.createDataFormat();

        headerStyle.setDataFormat(df_header.getFormat("text"));
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(CellStyle.ALIGN_CENTER);

        final CellStyle dateStyle = wb.createCellStyle();
        dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("mm/dd/yy"));
        dateStyle.setFont(defaultFont);//from  w  w  w.  jav a 2  s .c  o m

        final CellStyle textStyle = wb.createCellStyle();
        textStyle.setFont(defaultFont);

        final CellStyle amountStyle = wb.createCellStyle();
        amountStyle.setFont(defaultFont);
        amountStyle.setAlignment(CellStyle.ALIGN_RIGHT);

        final DecimalFormat format = (DecimalFormat) CommodityFormat
                .getFullNumberFormat(account.getCurrencyNode());
        final String pattern = format.toLocalizedPattern().replace("", account.getCurrencyNode().getPrefix());
        final DataFormat df = wb.createDataFormat();
        amountStyle.setDataFormat(df.getFormat(pattern));

        // Create headers
        int row = 0;
        Row r = s.createRow(row);
        for (int i = 0; i < columnNames.length; i++) {
            Cell c = r.createCell(i);
            c.setCellValue(createHelper.createRichTextString(columnNames[i]));
            c.setCellStyle(headerStyle);
        }

        // Dump the transactions
        for (final Transaction transaction : account.getTransactions(startDate, endDate)) {
            r = s.createRow(++row);

            int col = 0;

            // date
            Cell c = r.createCell(col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(DateUtils.asDate(transaction.getLocalDate()));
            c.setCellStyle(dateStyle);

            // number
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(transaction.getNumber());
            c.setCellStyle(textStyle);

            // payee
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(transaction.getPayee());
            c.setCellStyle(textStyle);

            // memo
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(transaction.getMemo());
            c.setCellStyle(textStyle);

            // account
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(getAccountColumnValue(transaction, account));
            c.setCellStyle(textStyle);

            // clr
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_STRING);
            c.setCellValue(transaction.getReconciled(account).toString());
            c.setCellStyle(textStyle);

            final BigDecimal amount = transaction.getAmount(account);

            // increase
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            if (amount.signum() >= 0) {
                c.setCellValue(amount.doubleValue());
            }
            c.setCellStyle(amountStyle);

            // decrease
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            if (amount.signum() < 0) {
                c.setCellValue(amount.abs().doubleValue());
            }
            c.setCellStyle(amountStyle);

            // balance
            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            c.setCellValue(account.getBalanceAt(transaction).doubleValue());
            c.setCellStyle(amountStyle);
        }

        // autosize the column widths
        final short columnCount = s.getRow(1).getLastCellNum();

        // autosize all of the columns + 10 pixels
        for (int i = 0; i <= columnCount; i++) {
            s.autoSizeColumn(i);
            s.setColumnWidth(i, s.getColumnWidth(i) + 10);
        }

        Logger.getLogger(AccountExport.class.getName()).log(Level.INFO, "{0} cell styles were used",
                wb.getNumCellStyles());

        // Save
        final String filename;

        if (wb instanceof XSSFWorkbook) {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xlsx";
        } else {
            filename = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".xls";
        }

        try (final FileOutputStream out = new FileOutputStream(filename)) {
            wb.write(out);
        } catch (final Exception e) {
            Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
        }

    } catch (IOException e) {
        Logger.getLogger(AccountExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}

From source file:jgnash.engine.budget.BudgetResultsExport.java

License:Open Source License

public static void exportBudgetResultsModel(final File file, final BudgetResultsModel model) {

    Resource rb = Resource.get();

    Workbook wb;//from   w w  w.j ava 2  s  . co  m

    String extension = FileUtils.getFileExtension(file.getAbsolutePath());

    if (extension.equals("xlsx")) {
        wb = new XSSFWorkbook();
    } else {
        wb = new HSSFWorkbook();
    }

    CreationHelper createHelper = wb.getCreationHelper();

    // create a new sheet
    Sheet s = wb.createSheet(model.getBudget().getName());

    // create header cell styles
    CellStyle headerStyle = wb.createCellStyle();

    // create 2 fonts objects
    Font amountFont = wb.createFont();
    Font headerFont = wb.createFont();

    amountFont.setFontHeightInPoints((short) 10);
    amountFont.setColor(IndexedColors.BLACK.getIndex());

    headerFont.setFontHeightInPoints((short) 11);
    headerFont.setColor(IndexedColors.BLACK.getIndex());
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    DataFormat df = wb.createDataFormat();

    // Set the other cell style and formatting
    headerStyle.setBorderBottom(CellStyle.BORDER_THIN);
    headerStyle.setBorderTop(CellStyle.BORDER_THIN);
    headerStyle.setBorderLeft(CellStyle.BORDER_THIN);
    headerStyle.setBorderRight(CellStyle.BORDER_THIN);
    headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    headerStyle.setDataFormat(df.getFormat("text"));
    headerStyle.setFont(headerFont);
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);

    int row = 0;
    Row r = s.createRow(row);

    // create period headers
    for (int i = 0; i < model.getDescriptorList().size(); i++) {
        Cell c = r.createCell(i * 3 + 1);
        c.setCellValue(
                createHelper.createRichTextString(model.getDescriptorList().get(i).getPeriodDescription()));
        c.setCellStyle(headerStyle);
        s.addMergedRegion(new CellRangeAddress(row, row, i * 3 + 1, i * 3 + 3));
    }

    {
        int col = model.getDescriptorList().size() * 3 + 1;
        Cell c = r.createCell(col);
        c.setCellValue(createHelper.createRichTextString(rb.getString("Title.Summary")));
        c.setCellStyle(headerStyle);
        s.addMergedRegion(new CellRangeAddress(row, row, col, col + 2));
    }

    // create results header columns
    row++;
    r = s.createRow(row);

    {
        Cell c = r.createCell(0);
        c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Account")));
        c.setCellStyle(headerStyle);

        for (int i = 0; i <= model.getDescriptorList().size(); i++) {
            c = r.createCell(i * 3 + 1);
            c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Budgeted")));
            c.setCellStyle(headerStyle);

            c = r.createCell(i * 3 + 2);
            c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Change")));
            c.setCellStyle(headerStyle);

            c = r.createCell(i * 3 + 3);
            c.setCellValue(createHelper.createRichTextString(rb.getString("Column.Remaining")));
            c.setCellStyle(headerStyle);
        }
    }

    // must sort the accounts, otherwise child structure is not correct
    List<Account> accounts = new ArrayList<>(model.getAccounts());
    Collections.sort(accounts);

    // create account rows
    for (Account account : accounts) {

        CellStyle amountStyle = wb.createCellStyle();
        amountStyle.setFont(amountFont);

        DecimalFormat format = (DecimalFormat) CommodityFormat.getFullNumberFormat(account.getCurrencyNode());
        String pattern = format.toLocalizedPattern().replace("", account.getCurrencyNode().getPrefix());
        amountStyle.setDataFormat(df.getFormat(pattern));

        row++;

        int col = 0;

        r = s.createRow(row);

        CellStyle cs = wb.createCellStyle();
        cs.cloneStyleFrom(headerStyle);
        cs.setAlignment(CellStyle.ALIGN_LEFT);
        cs.setIndention((short) (model.getDepth(account) * 2));

        Cell c = r.createCell(col);
        c.setCellValue(createHelper.createRichTextString(account.getName()));
        c.setCellStyle(cs);

        List<CellReference> budgetedRefList = new ArrayList<>();
        List<CellReference> changeRefList = new ArrayList<>();
        List<CellReference> remainingRefList = new ArrayList<>();

        for (int i = 0; i < model.getDescriptorList().size(); i++) {

            BudgetPeriodResults results = model.getResults(model.getDescriptorList().get(i), account);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            c.setCellValue(results.getBudgeted().doubleValue());
            c.setCellStyle(amountStyle);

            CellReference budgetedRef = new CellReference(row, col);
            budgetedRefList.add(budgetedRef);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            c.setCellValue(results.getChange().doubleValue());
            c.setCellStyle(amountStyle);

            CellReference changeRef = new CellReference(row, col);
            changeRefList.add(changeRef);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_FORMULA);
            c.setCellStyle(amountStyle);
            c.setCellFormula(budgetedRef.formatAsString() + "-" + changeRef.formatAsString());

            CellReference remainingRef = new CellReference(row, col);
            remainingRefList.add(remainingRef);
        }

        // add summary columns                               
        addSummaryCell(r, ++col, budgetedRefList, amountStyle);
        addSummaryCell(r, ++col, changeRefList, amountStyle);
        addSummaryCell(r, ++col, remainingRefList, amountStyle);
    }

    // add group summary rows
    for (AccountGroup group : model.getAccountGroupList()) {

        CellStyle amountStyle = wb.createCellStyle();
        amountStyle.setFont(amountFont);
        amountStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        amountStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        amountStyle.setBorderBottom(CellStyle.BORDER_THIN);
        amountStyle.setBorderTop(CellStyle.BORDER_THIN);
        amountStyle.setBorderLeft(CellStyle.BORDER_THIN);
        amountStyle.setBorderRight(CellStyle.BORDER_THIN);

        DecimalFormat format = (DecimalFormat) CommodityFormat.getFullNumberFormat(model.getBaseCurrency());
        String pattern = format.toLocalizedPattern().replace("", model.getBaseCurrency().getPrefix());
        amountStyle.setDataFormat(df.getFormat(pattern));

        row++;

        int col = 0;

        r = s.createRow(row);

        CellStyle cs = wb.createCellStyle();
        cs.cloneStyleFrom(headerStyle);
        cs.setAlignment(CellStyle.ALIGN_LEFT);

        Cell c = r.createCell(col);
        c.setCellValue(createHelper.createRichTextString(group.toString()));
        c.setCellStyle(cs);

        List<CellReference> budgetedRefList = new ArrayList<>();
        List<CellReference> changeRefList = new ArrayList<>();
        List<CellReference> remainingRefList = new ArrayList<>();

        for (int i = 0; i < model.getDescriptorList().size(); i++) {

            BudgetPeriodResults results = model.getResults(model.getDescriptorList().get(i), group);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            c.setCellValue(results.getBudgeted().doubleValue());
            c.setCellStyle(amountStyle);

            CellReference budgetedRef = new CellReference(row, col);
            budgetedRefList.add(budgetedRef);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_NUMERIC);
            c.setCellValue(results.getChange().doubleValue());
            c.setCellStyle(amountStyle);

            CellReference changeRef = new CellReference(row, col);
            changeRefList.add(changeRef);

            c = r.createCell(++col);
            c.setCellType(Cell.CELL_TYPE_FORMULA);
            c.setCellStyle(amountStyle);
            c.setCellFormula(budgetedRef.formatAsString() + "-" + changeRef.formatAsString());

            CellReference remainingRef = new CellReference(row, col);
            remainingRefList.add(remainingRef);
        }

        // add summary columns                               
        addSummaryCell(r, ++col, budgetedRefList, amountStyle);
        addSummaryCell(r, ++col, changeRefList, amountStyle);
        addSummaryCell(r, ++col, remainingRefList, amountStyle);
    }

    // force evaluation
    FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
    evaluator.evaluateAll();

    short columnCount = s.getRow(1).getLastCellNum();

    // autosize all of the columns + 10 pixels
    for (int i = 0; i <= columnCount; i++) {
        s.autoSizeColumn(i);
        s.setColumnWidth(i, s.getColumnWidth(i) + 10);
    }

    // Save
    String filename = file.getAbsolutePath();

    if (wb instanceof XSSFWorkbook) {
        filename = FileUtils.stripFileExtension(filename) + ".xlsx";
    } else {
        filename = FileUtils.stripFileExtension(filename) + ".xls";
    }

    try (FileOutputStream out = new FileOutputStream(filename)) {
        wb.write(out);
    } catch (Exception e) {
        Logger.getLogger(BudgetResultsExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}

From source file:ke.co.mspace.nonsmppmanager.service.SMSOutServiceImpl.java

private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();//w w w  .j  a v  a  2s .  co  m
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}

From source file:ke.co.tawi.babblesms.server.utils.export.topups.AllTopupsExportUtil.java

License:Open Source License

/**
 *
 * @param wb/*w  w w.  j av a 2s.  c o m*/
 * @return CellStyle
 */
public static CellStyle createBorderedStyle(Workbook wb) {
    CellStyle style = wb.createCellStyle();
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());

    return style;
}

From source file:main.resources.FileExcel.java

public static void generaXlsx() throws IOException {

    //nombre del archivo de Excel
    String nombreArchivo = "quincena.xlsx";

    String nombreHoja1 = "fecha";//nombre de la hoja1

    Workbook libroTrabajo = new XSSFWorkbook();
    Sheet hoja1 = libroTrabajo.createSheet(nombreHoja1);

    Row row = hoja1.createRow((short) 1);
    //row.setHeightInPoints(10); //alto de celda

    Cell cell = row.createCell((short) 1);
    Cell cell1 = row.createCell((short) 1);
    cell.setCellValue("Asistencia fecha xxxxxx");
    CellStyle cellStyle = libroTrabajo.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    //cellStyle.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex());
    //cellStyle.setFillPattern(CellStyle.BIG_SPOTS);
    cellStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
    cellStyle.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex());
    cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
    cellStyle.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex());
    cellStyle.setBorderRight(CellStyle.BORDER_THIN);
    cellStyle.setRightBorderColor(IndexedColors.AUTOMATIC.getIndex());
    cellStyle.setBorderTop(CellStyle.BORDER_THIN);
    cellStyle.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex());

    hoja1.addMergedRegion(new CellRangeAddress(1, // first row (0-based) primera fila
            1, //lasto row (0-based) ultima fila
            1, //first column (0-based) numero de columna inicial
            5 //last column (0-based) numero de columna final
    ));/* w  w w.j  av  a 2 s. c o  m*/
    cell.setCellStyle(cellStyle);
    cell1.setCellStyle(cellStyle);

    //escribir este libro en un OutputStream.
    try (FileOutputStream fileOut = new FileOutputStream(nombreArchivo)) {
        //escribir este libro en un OutputStream.
        libroTrabajo.write(fileOut);
        fileOut.flush();
    }
}

From source file:main.resources.FileExcel.java

public void excelDia() throws FileNotFoundException, IOException {
    String nombreFile = "quincena.xlsx";
    String nombreHoja = "dia x mes x ao x";

    Workbook libro = new XSSFWorkbook();
    Sheet hoja = libro.createSheet(nombreHoja);

    Font negrita = libro.createFont();
    negrita.setBoldweight(Font.BOLDWEIGHT_BOLD);

    CellStyle estilo = libro.createCellStyle();
    estilo.setAlignment(CellStyle.ALIGN_CENTER);
    estilo.setFillForegroundColor(IndexedColors.GREEN.getIndex());
    estilo.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estilo.setBorderBottom(CellStyle.BORDER_THIN);
    estilo.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo.setBorderLeft(CellStyle.BORDER_THIN);
    estilo.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo.setBorderRight(CellStyle.BORDER_THIN);
    estilo.setRightBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo.setBorderTop(CellStyle.BORDER_THIN);
    estilo.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo.setFont(negrita);//  www  .  j  a  v  a2s  .com

    CellStyle bordes = libro.createCellStyle();
    bordes.setAlignment(CellStyle.ALIGN_LEFT);
    bordes.setBorderBottom(CellStyle.BORDER_THIN);
    bordes.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex());
    bordes.setBorderLeft(CellStyle.BORDER_THIN);
    bordes.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex());
    bordes.setBorderRight(CellStyle.BORDER_THIN);
    bordes.setRightBorderColor(IndexedColors.AUTOMATIC.getIndex());
    bordes.setBorderTop(CellStyle.BORDER_THIN);
    bordes.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex());

    CellStyle estilo2 = libro.createCellStyle();
    estilo2.setAlignment(CellStyle.ALIGN_CENTER);
    estilo2.setBorderBottom(CellStyle.BORDER_THIN);
    estilo2.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo2.setBorderLeft(CellStyle.BORDER_THIN);
    estilo2.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo2.setBorderRight(CellStyle.BORDER_THIN);
    estilo2.setRightBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo2.setBorderTop(CellStyle.BORDER_THIN);
    estilo2.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex());
    estilo2.setAlignment(CellStyle.ALIGN_CENTER);
    estilo2.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
    estilo2.setFillPattern(CellStyle.SOLID_FOREGROUND);
    estilo2.setFont(negrita);

    CellStyle borderBot = libro.createCellStyle();
    borderBot.setBorderBottom(CellStyle.BORDER_THIN);
    borderBot.setBottomBorderColor(IndexedColors.AUTOMATIC.getIndex());

    Row row = hoja.createRow(1);

    //Row row1 = hoja.createRow(2);

    //empleados faltas
    Appi app = new Appi();
    Date Fecha = new Date();
    DateFormat formato = new SimpleDateFormat("YYYY-MM-dd");
    String fechaActual = formato.format(Fecha);
    ArrayList<Empleado> faltas = app.faltas(fechaActual);//obtengo listado de empleados
    String grupoBandera = "";
    String maestro = "";
    int pRow = 3;
    if (!faltas.isEmpty()) {
        Cell celda = row.createCell(3);
        Cell celda2 = row.createCell(4);
        Cell celda3 = row.createCell(5);
        Cell celda4 = row.createCell(6);
        Cell celda5 = row.createCell(7);
        combinarceldas(hoja, 1, 1, 3, 7);
        celda.setCellValue("Asistencia " + fechaActual);
        celda.setCellStyle(estilo);
        celda2.setCellStyle(estilo);
        celda3.setCellStyle(estilo);
        celda4.setCellStyle(estilo);
        celda5.setCellStyle(estilo);
        grupoBandera = faltas.get(0).getGrupo();

        //encabezados
        Row row2 = hoja.createRow(pRow);
        Cell cell = row2.createCell(1);
        cell.setCellValue("Nficha");
        cell.setCellStyle(estilo2);

        Cell cell1 = row2.createCell(2);
        cell1.setCellValue("1er Apellido");
        cell1.setCellStyle(estilo2);

        Cell cell2 = row2.createCell(3);
        cell2.setCellValue("2do Apellido");
        cell2.setCellStyle(estilo2);

        Cell cell3 = row2.createCell(4);
        cell3.setCellValue("1er Nombre");
        cell3.setCellStyle(estilo2);

        Cell cell4 = row2.createCell(5);
        cell4.setCellValue("2do Nombre");
        cell4.setCellStyle(estilo2);

        Cell cell5 = row2.createCell(6);
        cell5.setCellValue("Identificacion");
        cell5.setCellStyle(estilo2);

        Cell cell6 = row2.createCell(7);
        cell6.setCellValue("Da");
        cell6.setCellStyle(estilo2);

        Cell cell7 = row2.createCell(8);
        cell7.setCellValue("Cargo");
        cell7.setCellStyle(estilo2);

        Cell cell8 = row2.createCell(9);
        cell8.setCellValue("Grupo");
        cell8.setCellStyle(estilo2);
    }
    Empleado emp = null;
    for (int i = 0; i < faltas.size(); i++) {

        //datos
        emp = (Empleado) faltas.get(i);
        Grupo grupo = app.grupo(emp.getGrupo());

        if (!grupoBandera.equals(emp.getGrupo())) {
            grupoBandera = emp.getGrupo();
            pRow = pRow + 2;
            //frima maestro
            Row row4 = hoja.createRow(pRow);
            Cell celda9 = row4.createCell(1);
            combinarceldas(hoja, pRow, pRow, 1, 3);
            celda9.setCellValue("Maestro Grupo:");
            celda9.setCellStyle(estilo);
            Cell celda10 = row4.createCell(2);
            celda10.setCellStyle(bordes);
            Cell celda11 = row4.createCell(3);
            celda11.setCellStyle(bordes);
            Cell celda12 = row4.createCell(4);
            celda12.setCellStyle(borderBot);
            Cell celda13 = row4.createCell(5);
            celda13.setCellStyle(borderBot);
            Cell celda14 = row4.createCell(6);
            celda14.setCellStyle(borderBot);
            Cell celda15 = row4.createCell(7);
            celda15.setCellStyle(borderBot);
            Cell celda16 = row4.createCell(8);
            celda16.setCellStyle(borderBot);

            pRow++;

            Row row6 = hoja.createRow(pRow);
            Cell celda64 = row6.createCell(4);
            combinarceldas(hoja, pRow, pRow, 4, 8);
            celda64.setCellValue(maestro);

            pRow = pRow + 2;
            //encabexzados
            Row row2 = hoja.createRow(pRow);
            Cell cell = row2.createCell(1);
            cell.setCellValue("Nficha");
            cell.setCellStyle(estilo2);

            Cell cell1 = row2.createCell(2);
            cell1.setCellValue("1er Apellido");
            cell1.setCellStyle(estilo2);

            Cell cell2 = row2.createCell(3);
            cell2.setCellValue("2do Apellido");
            cell2.setCellStyle(estilo2);

            Cell cell3 = row2.createCell(4);
            cell3.setCellValue("1er Nombre");
            cell3.setCellStyle(estilo2);

            Cell cell4 = row2.createCell(5);
            cell4.setCellValue("2do Nombre");
            cell4.setCellStyle(estilo2);

            Cell cell5 = row2.createCell(6);
            cell5.setCellValue("Identificacion");
            cell5.setCellStyle(estilo2);

            Cell cell6 = row2.createCell(7);
            cell6.setCellValue("Da");
            cell6.setCellStyle(estilo2);

            Cell cell7 = row2.createCell(8);
            cell7.setCellValue("Cargo");
            cell7.setCellStyle(estilo2);

            Cell cell8 = row2.createCell(9);
            cell8.setCellValue("Grupo");
            cell8.setCellStyle(estilo2);
        }

        Row row5 = hoja.createRow(pRow + 1);
        Cell celda51 = row5.createCell(1);
        celda51.setCellStyle(bordes);
        celda51.setCellValue(emp.getnFicha());
        Cell celda52 = row5.createCell(2);
        celda52.setCellStyle(bordes);
        celda52.setCellValue(emp.getpApellido());
        Cell celda53 = row5.createCell(3);
        celda53.setCellStyle(bordes);
        celda53.setCellValue(emp.getsApellido());
        Cell celda54 = row5.createCell(4);
        celda54.setCellStyle(bordes);
        celda54.setCellValue(emp.getpNombre());
        Cell celda55 = row5.createCell(5);
        celda55.setCellStyle(bordes);
        celda55.setCellValue(emp.getsNombre());
        Cell celda56 = row5.createCell(6);
        celda56.setCellStyle(bordes);
        celda56.setCellValue(emp.getCedula());
        Cell celda57 = row5.createCell(7);
        celda57.setCellStyle(bordes);
        celda57.setCellValue(fechaActual);
        Cell celda58 = row5.createCell(8);
        celda58.setCellStyle(bordes);
        celda58.setCellValue(emp.getCargo());
        Cell celda59 = row5.createCell(9);
        celda59.setCellStyle(bordes);
        celda59.setCellValue(grupo.getNombre());
        pRow++;
        Empleado supervisor = app.empleado(grupo.getSupervisor());
        if (supervisor != null) {
            maestro = supervisor.getpNombre() + " " + supervisor.getsNombre() + " " + supervisor.getpApellido()
                    + " " + supervisor.getsApellido();
        } else {
            maestro = String.valueOf(grupo.getSupervisor());
        }

        //
        //String cedula = (String) e;
        //Empleado emp = app.empleado(cedula);

        System.out.println(emp.getCedula());

    }
    if (emp != null) {
        pRow = pRow + 2;
        //frima maestro
        Row row4 = hoja.createRow(pRow);
        Cell celda9 = row4.createCell(1);
        combinarceldas(hoja, pRow, pRow, 1, 3);
        celda9.setCellValue("Maestro Grupo:");
        celda9.setCellStyle(estilo);
        Cell celda10 = row4.createCell(2);
        celda10.setCellStyle(bordes);
        Cell celda11 = row4.createCell(3);
        celda11.setCellStyle(bordes);
        Cell celda12 = row4.createCell(4);
        celda12.setCellStyle(borderBot);
        Cell celda13 = row4.createCell(5);
        celda13.setCellStyle(borderBot);
        Cell celda14 = row4.createCell(6);
        celda14.setCellStyle(borderBot);
        Cell celda15 = row4.createCell(7);
        celda15.setCellStyle(borderBot);
        Cell celda16 = row4.createCell(8);
        celda16.setCellStyle(borderBot);

        pRow++;

        Row row6 = hoja.createRow(pRow);
        Cell celda64 = row6.createCell(4);
        combinarceldas(hoja, pRow, pRow, 4, 8);
        celda64.setCellValue(maestro);
    }

    //enmcabezados

    //Row row3 = hoja.createRow(1);
    // debe ejcutarse un loop de acuerdoa consaulta
    //datos

    //datos responsable firma

    //CellS
    //celda64.setCellStyle();

    try (FileOutputStream fileOut = new FileOutputStream(nombreFile)) {
        //escribir este libro en un OutputStream.
        libro.write(fileOut);
        fileOut.flush();
    }

}

From source file:model.Reports.java

private static Map<String, CellStyle> createStyles(Workbook wb) {

    Map<String, CellStyle> styles = new HashMap<>();
    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();//ww w.  j a v  a 2  s  . com
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFont(titleFont);
    styles.put("title", style);

    Font monthFont = wb.createFont();
    monthFont.setFontHeightInPoints((short) 11);
    monthFont.setColor(IndexedColors.WHITE.getIndex());
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(monthFont);
    style.setWrapText(true);
    styles.put("header", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setRightBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderLeft(CellStyle.BORDER_THIN);
    style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderTop(CellStyle.BORDER_THIN);
    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    styles.put("cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
    styles.put("formula_2", style);

    return styles;
}