Example usage for org.apache.poi.ss.usermodel HorizontalAlignment RIGHT

List of usage examples for org.apache.poi.ss.usermodel HorizontalAlignment RIGHT

Introduction

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

Prototype

HorizontalAlignment RIGHT

To view the source code for org.apache.poi.ss.usermodel HorizontalAlignment RIGHT.

Click Source Link

Document

The horizontal alignment is right-aligned, meaning that cell contents are aligned at the right edge of the cell, even in Right-to-Left mode.

Usage

From source file:org.jboss.windup.reporting.spreadsheet.ScorecardReporter.java

License:Open Source License

private static void appendMentoringTotalRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum, int start, int end) {
    Font boldFont = wb.createFont();
    boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    boldFont.setColor((short) 0x0);

    XSSFCellStyle commentCell = wb.createCellStyle();
    commentCell.setBorderTop(CellStyle.BORDER_THIN);

    XSSFCellStyle totalCell = wb.createCellStyle();
    totalCell.setBorderTop(CellStyle.BORDER_THIN);
    totalCell.setFont(boldFont);/*from   www. jav  a2  s . co m*/

    XSSFCellStyle totalCellRight = wb.createCellStyle();
    totalCellRight.setBorderTop(CellStyle.BORDER_THIN);
    totalCellRight.setAlignment(HorizontalAlignment.RIGHT);
    totalCellRight.setFont(boldFont);

    XSSFRow row = sheet.createRow(rowNum);
    XSSFCell t1 = row.createCell(0);
    t1.setCellValue("Total:");
    t1.setCellStyle(totalCellRight);

    XSSFCell t2 = row.createCell(1);
    t2.setCellFormula("SUM(B" + start + ":B" + end + ")");
    t2.setCellStyle(totalCell);

    XSSFCell t3 = row.createCell(2);
    t3.setCellStyle(totalCell);

    XSSFCell t4 = row.createCell(3);
    t4.setCellStyle(commentCell);
}

From source file:org.jboss.windup.reporting.spreadsheet.ScorecardReporter.java

License:Open Source License

private static void appendNotesRow(XSSFWorkbook wb, XSSFSheet sheet, int rowNum, String app, double effort,
        String notes) {/*from   w  ww  .ja  v  a  2 s .co  m*/
    XSSFRow row = sheet.createRow(rowNum);
    XSSFCell t1 = row.createCell(0);
    t1.setCellValue(app);

    XSSFCell t2 = row.createCell(1);
    XSSFCellStyle t2s = wb.createCellStyle();
    t2s.setAlignment(HorizontalAlignment.RIGHT);
    t2.setCellStyle(t2s);

    t2.setCellValue(effort);
    row.createCell(2);

    XSSFCell t4 = row.createCell(3);
    t4.setCellValue(notes);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.HSSFCellStyleProducer.java

License:Open Source License

/**
 * Converts the given element alignment into one of the HorizontalAlignment-constants.
 *
 * @param e the JFreeReport element alignment.
 * @return the HorizontalAlignment-Alignment.
 * @throws IllegalArgumentException if an Unknown JFreeReport alignment is given.
 *//*  ww w  .  j  av a 2  s.  c  om*/
protected static HorizontalAlignment convertHorizontalAlignment(final ElementAlignment e) {
    if (ElementAlignment.LEFT.equals(e)) {
        return HorizontalAlignment.LEFT;
    } else if (ElementAlignment.RIGHT.equals(e)) {
        return HorizontalAlignment.RIGHT;
    } else if (ElementAlignment.JUSTIFY.equals(e)) {
        return HorizontalAlignment.JUSTIFY;
    } else if (ElementAlignment.CENTER.equals(e)) {
        return HorizontalAlignment.CENTER;
    }

    throw new IllegalArgumentException("Invalid alignment");
}

From source file:org.primefaces.extensions.showcase.util.ExcelCustomExporter.java

License:Apache License

protected CellStyle addColumnAlignments(UIComponent component, CellStyle style) {
    if (component instanceof HtmlOutputText) {
        HtmlOutputText output = (HtmlOutputText) component;
        if (output.getStyle() != null && output.getStyle().contains("left")) {
            style.setAlignment(HorizontalAlignment.LEFT);
        }/*from   w  ww. java2  s . co  m*/
        if (output.getStyle() != null && output.getStyle().contains("right")) {
            style.setAlignment(HorizontalAlignment.RIGHT);
        }
        if (output.getStyle() != null && output.getStyle().contains("center")) {
            style.setAlignment(HorizontalAlignment.CENTER);
        }
    }
    return style;
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

public XLSPrinter(OutputStream output, boolean checkLast) {
    iOutput = output;/*from   w ww.  java 2s.  c o m*/
    iCheckLast = checkLast;
    iWorkbook = new HSSFWorkbook();
    iSheet = iWorkbook.createSheet();
    iSheet.setDisplayGridlines(false);
    iSheet.setPrintGridlines(false);
    iSheet.setFitToPage(true);
    iSheet.setHorizontallyCenter(true);
    PrintSetup printSetup = iSheet.getPrintSetup();
    printSetup.setLandscape(true);
    iSheet.setAutobreaks(true);
    printSetup.setFitHeight((short) 1);
    printSetup.setFitWidth((short) 1);
    iStyles = new HashMap<String, CellStyle>();

    CellStyle style;

    style = iWorkbook.createCellStyle();
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFont(getFont(true, false, false, Color.BLACK));
    style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setWrapText(true);
    iStyles.put("header", style);

    style = iWorkbook.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFont(getFont(false, false, false, Color.BLACK));
    style.setWrapText(true);
    iStyles.put("plain", style);

    style = iWorkbook.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.TOP);
    style.setFont(getFont(false, false, false, Color.BLACK));
    iStyles.put("number", style);
}

From source file:org.unitime.timetable.export.XLSPrinter.java

License:Apache License

protected CellStyle getStyle(A f, boolean dashed, String format) {
    String styleId = (dashed ? "D" : "") + (f.has(F.BOLD) ? "b" : "") + (f.has(F.ITALIC) ? "i" : "")
            + (f.has(F.UNDERLINE) ? "u" : "") + (f.has(F.RIGHT) ? "R" : f.has(F.CENTER) ? "C" : "L")
            + (f.hasColor() ? "#" + Integer.toHexString(f.getColor().getRGB()) : "")
            + (format == null ? "" : "|" + format);
    CellStyle style = iStyles.get(styleId);
    if (style == null) {
        style = iWorkbook.createCellStyle();
        if (dashed) {
            style.setBorderTop(BorderStyle.DASHED);
            style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        }/*from  w  w w . ja v a 2s . c o  m*/
        style.setAlignment(f.has(F.RIGHT) ? HorizontalAlignment.RIGHT
                : f.has(F.CENTER) ? HorizontalAlignment.CENTER : HorizontalAlignment.LEFT);
        style.setVerticalAlignment(VerticalAlignment.TOP);
        style.setFont(getFont(f.has(F.BOLD), f.has(F.ITALIC), f.has(F.UNDERLINE), f.getColor()));
        style.setWrapText(true);
        if (format != null)
            style.setDataFormat(iWorkbook.createDataFormat().getFormat(format));
        iStyles.put(styleId, style);
    }
    return style;
}

From source file:ro.dabuno.office.integration.BusinessPlan.java

License:Apache License

/**
 * create a library of cell styles//from   w w  w .  ja  va2  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:ro.dabuno.office.integration.LoadCalculator.java

/**
 * cell styles used for formatting calendar sheets
 *//*from   w w  w . j  av  a 2 s  .c  o m*/
private static Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style;
    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setFont(titleFont);
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    styles.put("title", style);

    Font itemFont = wb.createFont();
    itemFont.setFontHeightInPoints((short) 9);
    itemFont.setFontName("Trebuchet MS");
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.LEFT);
    style.setFont(itemFont);
    styles.put("item_left", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    styles.put("item_right", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(
            wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));
    styles.put("input_$", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));
    styles.put("input_%", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    styles.put("input_i", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setFont(itemFont);
    style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));
    styles.put("input_d", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("formula_$", style);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setBorderRight(BorderStyle.DOTTED);
    style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.DOTTED);
    style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.DOTTED);
    style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setDataFormat(wb.createDataFormat().getFormat("0"));
    style.setBorderBottom(BorderStyle.DOTTED);
    style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles.put("formula_i", style);

    return styles;
}

From source file:tr.org.liderahenk.liderconsole.core.utils.SWTResourceManager.java

License:Open Source License

private static XSSFWorkbook createWorkbookFromTable(TableViewer tableViewer, String sheetName) {

    // Create workbook & sheet
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet(sheetName == null ? "Sheet1" : sheetName);

    // Shade the background of the header row
    XSSFCellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFillForegroundColor(IndexedColors.LEMON_CHIFFON.getIndex());
    headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    headerStyle.setBorderTop(CellStyle.BORDER_THIN);
    headerStyle.setBorderBottom(CellStyle.BORDER_THIN);
    headerStyle.setBorderLeft(CellStyle.BORDER_THIN);
    headerStyle.setBorderRight(CellStyle.BORDER_THIN);
    headerStyle.setAlignment(HorizontalAlignment.CENTER);

    // Add header row
    Table table = tableViewer.getTable();
    TableColumn[] columns = table.getColumns();
    int rowIndex = 0;
    int cellIndex = 0;
    XSSFRow header = sheet.createRow((short) rowIndex++);
    for (TableColumn column : columns) {
        XSSFCell cell = header.createCell(cellIndex++);
        cell.setCellValue(column.getText());
        cell.setCellStyle(headerStyle);/*  w w w.  java2s .  c o  m*/
    }

    // Add data rows
    TableItem[] items = tableViewer.getTable().getItems();
    for (TableItem item : items) {
        // create a new row
        XSSFRow row = sheet.createRow((short) rowIndex++);
        cellIndex = 0;

        for (int i = 0; i < columns.length; i++) {
            // Create a new cell
            XSSFCell cell = row.createCell(cellIndex++);
            String text = item.getText(i);

            // Set the horizontal alignment (default to RIGHT)
            XSSFCellStyle cellStyle = wb.createCellStyle();
            if (LiderCoreUtils.isInteger(text)) {
                cellStyle.setAlignment(HorizontalAlignment.RIGHT);
            } else if (LiderCoreUtils.isValidDate(text,
                    ConfigProvider.getInstance().get(LiderConstants.CONFIG.DATE_FORMAT))) {
                cellStyle.setAlignment(HorizontalAlignment.CENTER);
            } else {
                cellStyle.setAlignment(HorizontalAlignment.LEFT);
            }
            cell.setCellStyle(cellStyle);

            // Set the cell's value
            cell.setCellValue(text);
        }
    }

    // Auto-fit the columns
    for (int i = 0; i < columns.length; i++) {
        sheet.autoSizeColumn((short) i);
    }

    return wb;
}

From source file:uk.co.certait.htmlexporter.writer.excel.ExcelStyleGenerator.java

License:Apache License

protected void applyHorizontalAlignment(Style style, XSSFCellStyle cellStyle) {
    if (style.isHorizontallyAlignedLeft()) {
        cellStyle.setAlignment(HorizontalAlignment.LEFT);
    } else if (style.isHorizontallyAlignedRight()) {
        cellStyle.setAlignment(HorizontalAlignment.RIGHT);
    } else if (style.isHorizontallyAlignedCenter()) {
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
    }/*from   w w  w  .ja  v a2s. com*/
}