Example usage for org.apache.poi.xssf.usermodel XSSFFont setFontHeightInPoints

List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setFontHeightInPoints

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFFont setFontHeightInPoints.

Prototype

public void setFontHeightInPoints(short height) 

Source Link

Document

set the font height in points.

Usage

From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java

License:Open Source License

private static void createRow(XSSFSheet worksheet, XSSFWorkbook workbook, ArticleStock article,
        CatalogueService catalogueService, int rowNumber) throws IOException {

    int col = 0;/*from  w  w  w  . j  a va 2 s.  c  om*/
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setBorderBottom(BorderStyle.THIN);
    cellStyle.setBorderLeft(BorderStyle.THIN);
    cellStyle.setBorderRight(BorderStyle.THIN);
    cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFCellStyle cellImageStyle = workbook.createCellStyle();
    cellImageStyle.setBorderBottom(BorderStyle.THIN);
    cellImageStyle.setBorderLeft(BorderStyle.THIN);
    cellImageStyle.setBorderRight(BorderStyle.THIN);
    cellImageStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    cellImageStyle.setAlignment(HorizontalAlignment.CENTER);

    if (rowNumber != 1) {
        cellStyle.setBorderTop(BorderStyle.THIN);
    }

    XSSFFont txtFont = workbook.createFont();
    txtFont.setFontName("calibri");
    txtFont.setFontHeightInPoints((short) 9);
    txtFont.setBold(false);
    cellStyle.setFont(txtFont);

    XSSFRow row = worksheet.createRow(rowNumber);
    row.setHeight((short) ROW_HEIGHT_TWIPS);//80px 1600
    // Photo
    File image = null;

    try {
        image = catalogueService.getFilePieceJointe(article.getArticleCatalogue().getPhotoArticleCatalogue());
    } catch (IllegalArgumentException e) {
        log.warn("No image to display for article " + article.getArticleCatalogue().getLibelle());
    }
    XSSFCell cell = row.createCell(col);
    cell.setCellStyle(cellImageStyle);

    if (image != null)
        addImage(workbook, worksheet, image, rowNumber);
    col = col + 1;

    // Rfrence
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getReferenceArticleStock());

    // Libell
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getArticleCatalogue().getLibelle());

    // Appock Stock
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    col = col + 1;
    cell.setCellValue(article.getQuantiteStock());
    cell.setCellType(CellType.NUMERIC);

    // Stock reel
    cell = row.createCell(col);
    cell.setCellStyle(cellStyle);
    cell.setCellType(CellType.NUMERIC);

}

From source file:net.mcnewfamily.rmcnew.model.excel.FontEssence.java

License:Open Source License

public XSSFFont toXSSFFont(XSSFWorkbook workbook) {
    XSSFFont xssfFont = null;
    if (workbook != null) {
        xssfFont = workbook.createFont();
        xssfFont.setCharSet(FontCharset.DEFAULT);
        xssfFont.setFamily(this.fontFamily);
        xssfFont.setBold(this.bold);
        if (this.bold) {
            xssfFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        } else {/* w  ww.  jav a2  s . com*/
            xssfFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);
        }
        xssfFont.setItalic(this.italic);
        if (this.underline) {
            xssfFont.setUnderline(FontUnderline.SINGLE);
        }
        xssfFont.setStrikeout(this.strikeout);
        xssfFont.setColor(this.color);
        xssfFont.setFontHeightInPoints(this.fontHeightInPoints);
    } else {
        throw new IllegalArgumentException("Cannot create XSSFFont in a null XSSFWorkbook!");
    }
    return xssfFont;
}

From source file:org.agmip.ui.afsirs.util.SummaryReportExcelFormat.java

private XSSFCellStyle getCellStyle(int type) {
    XSSFFont font = workbook.createFont();
    XSSFCellStyle style = null;//from  w  ww . j a  v a  2  s.c  o m

    switch (type) {
    case 1:
        font.setFontHeightInPoints((short) 15);
        font.setFontName("IMPACT");
        font.setItalic(true);
        font.setColor(HSSFColor.BLUE.index);
        style = workbook.createCellStyle();
        style.setWrapText(true);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setFont(font);
        break;

    case 2:
        font.setFontHeightInPoints((short) 15);
        font.setFontName("IMPACT");
        font.setItalic(true);
        font.setColor(HSSFColor.BLUE.index);
        style = workbook.createCellStyle();
        style.setWrapText(true);
        style.setShrinkToFit(true);
        style.setFont(font);
        break;

    case 3:
        font.setFontHeightInPoints((short) 15);
        font.setFontName("IMPACT");
        font.setItalic(true);
        font.setColor(HSSFColor.BLUE.index);
        style = workbook.createCellStyle();
        style.setWrapText(true);
        style.setShrinkToFit(true);
        style.setFont(font);
        break;

    case 4:
        font.setFontHeightInPoints((short) 15);
        font.setFontName("IMPACT");
        font.setItalic(true);
        font.setColor(HSSFColor.BLUE.index);
        style = workbook.createCellStyle();
        style.setWrapText(true);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setFont(font);
        break;

    case 5:
        font.setFontHeightInPoints((short) 15);
        font.setFontName("IMPACT");
        font.setItalic(true);
        font.setColor(HSSFColor.BLUE.index);
        style = workbook.createCellStyle();
        style.setWrapText(true);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setFont(font);
        break;

    }

    return style;
}

From source file:org.apache.fineract.accounting.closure.storeglaccountbalance.service.GLClosureJournalEntryBalanceReadPlatformServiceImpl.java

License:Apache License

/**
 * Create the excel file with the balance report data
 * //from w w  w.  j a v a 2  s.  co  m
 * @param reportDataList
 * @return {@link File} object
 */
@SuppressWarnings("unused")
private File createGLClosureAccountBalanceReportExcelFile(
        final Collection<GLClosureAccountBalanceReportData> reportDataList) {
    File file = null;

    try {
        if (reportDataList != null) {
            final String[] columnTitles = new String[13];

            columnTitles[0] = "AccountCostCentre";
            columnTitles[1] = "AccountDepartment";
            columnTitles[2] = "AccountNumber";
            columnTitles[3] = "TransactionType";
            columnTitles[4] = "TransactionDate";
            columnTitles[5] = "GoodsAmount";
            columnTitles[6] = "Reference";
            columnTitles[7] = "Narrative";
            columnTitles[8] = "UniqueReferenceNumber";
            columnTitles[9] = "UserNumber";
            columnTitles[10] = "Source";
            columnTitles[11] = "PostedDate";
            columnTitles[12] = "TransactionAnalysisCode";

            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet spreadsheet = workbook.createSheet(" nominaltransactions ");
            XSSFRow row;
            XSSFFont font;
            XSSFCellStyle style;
            XSSFDataFormat dataFormat;

            int rowId = 0;
            int cellId = 0;

            row = spreadsheet.createRow(rowId++);

            for (String columnTitle : columnTitles) {
                font = workbook.createFont();
                style = workbook.createCellStyle();

                font.setBold(true);
                font.setFontName("Arial");
                font.setFontHeightInPoints((short) 10);
                style.setFont(font);

                Cell cell = row.createCell(cellId++);

                cell.setCellValue(columnTitle);
                cell.setCellStyle(style);
            }

            for (GLClosureAccountBalanceReportData reportData : reportDataList) {
                row = spreadsheet.createRow(rowId++);
                font = workbook.createFont();
                dataFormat = workbook.createDataFormat();

                font.setFontName("Arial");
                font.setFontHeightInPoints((short) 10);
                font.setBold(false);

                // ====================================================
                Cell cell = row.createCell(2);
                style = workbook.createCellStyle();

                cell.setCellType(Cell.CELL_TYPE_STRING);
                style.setDataFormat(dataFormat.getFormat("@"));
                style.setFont(font);
                cell.setCellValue(reportData.getAccountNumber());
                cell.setCellStyle(style);
                // ====================================================

                // ====================================================
                if (reportData.getTransactionType() != null) {
                    cell = row.createCell(3);
                    style = workbook.createCellStyle();

                    style.setFont(font);
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(reportData.getTransactionType().getValue());
                    cell.setCellStyle(style);
                }
                // ====================================================

                // ====================================================
                if (reportData.getTransactionDate() != null) {
                    cell = row.createCell(4);
                    style = workbook.createCellStyle();

                    Date transactionDate = reportData.getTransactionDate().toDate();

                    style.setDataFormat(dataFormat.getFormat("MM/DD/YY"));
                    style.setFont(font);
                    cell.setCellValue(transactionDate);
                    cell.setCellStyle(style);
                }
                // ====================================================

                // ====================================================
                if (reportData.getAmount() != null) {
                    cell = row.createCell(5);
                    style = workbook.createCellStyle();

                    Double amount = reportData.getAmount().doubleValue();

                    style.setDataFormat(dataFormat.getFormat("0.00"));
                    style.setFont(font);
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(amount);
                    cell.setCellStyle(style);
                }
                // ====================================================

                // ====================================================
                if (reportData.getReference() != null) {
                    cell = row.createCell(6);
                    style = workbook.createCellStyle();

                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    style.setDataFormat(dataFormat.getFormat("@"));
                    style.setFont(font);
                    cell.setCellValue(reportData.getReference());
                    cell.setCellStyle(style);
                }
                // ====================================================

                // ====================================================
                if (reportData.getPostedDate() != null) {
                    cell = row.createCell(11);
                    style = workbook.createCellStyle();

                    Date postedDate = reportData.getPostedDate().toDate();

                    style.setDataFormat(dataFormat.getFormat("MM/DD/YY"));
                    style.setFont(font);
                    cell.setCellValue(postedDate);
                    cell.setCellStyle(style);
                }
                // ====================================================
            }

            final String fileDirectory = FileSystemContentRepository.MIFOSX_BASE_DIR + File.separator + "";

            if (!new File(fileDirectory).isDirectory()) {
                new File(fileDirectory).mkdirs();
            }

            file = new File(fileDirectory + "gl_closure_account_balance_report.xls");

            FileOutputStream fileOutputStream = new FileOutputStream(file);

            workbook.write(fileOutputStream);

            fileOutputStream.close();
        }
    }

    catch (Exception exception) {
        logger.error(exception.getMessage(), exception);
    }

    return file;
}

From source file:org.apache.ofbiz.pricat.AbstractPricatParser.java

License:Apache License

public void writeCommentsToFile(XSSFWorkbook workbook, XSSFSheet sheet) {
    report.println();/*from w ww.j  a  v  a 2s .  c o  m*/
    report.print(UtilProperties.getMessage(resource, "WriteCommentsBackToExcel", locale),
            InterfaceReport.FORMAT_NOTE);
    FileOutputStream fos = null;
    XSSFCreationHelper factory = workbook.getCreationHelper();
    XSSFFont boldFont = workbook.createFont();
    boldFont.setFontName("Arial");
    boldFont.setBold(true);
    boldFont.setCharSet(134);
    boldFont.setFontHeightInPoints((short) 9);
    XSSFFont plainFont = workbook.createFont();
    plainFont.setFontName("Arial");
    plainFont.setCharSet(134);
    plainFont.setFontHeightInPoints((short) 9);

    XSSFSheet errorSheet = null;
    if (errorMessages.keySet().size() > 0) {
        String errorSheetName = UtilDateTime.nowDateString("yyyy-MM-dd HHmm") + " Errors";
        errorSheetName = WorkbookUtil.createSafeSheetName(errorSheetName);
        errorSheet = workbook.createSheet(errorSheetName);
        workbook.setSheetOrder(errorSheetName, 0);
        workbook.setActiveSheet(workbook.getSheetIndex(errorSheetName));
        XSSFDrawing drawingPatriarch = errorSheet.getDrawingPatriarch();
        if (drawingPatriarch == null) {
            drawingPatriarch = errorSheet.createDrawingPatriarch();
        }
        for (int i = 0; i <= getHeaderRowNo(); i++) {
            XSSFRow newRow = errorSheet.createRow(i);
            XSSFRow row = sheet.getRow(i);
            newRow.setHeight(row.getHeight());
            copyRow(row, newRow, factory, drawingPatriarch);
        }

        // copy merged regions
        for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
            CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
            if (mergedRegion.getFirstRow() < getHeaderRowNo()) {
                errorSheet.addMergedRegion(mergedRegion);
            }
        }

        // copy images
        List<XSSFPictureData> pics = workbook.getAllPictures();
        List<XSSFShape> shapes = sheet.getDrawingPatriarch().getShapes();
        for (int i = 0; i < shapes.size(); i++) {
            XSSFShape shape = shapes.get(i);
            XSSFAnchor anchor = shape.getAnchor();
            if (shape instanceof XSSFPicture && anchor instanceof XSSFClientAnchor) {
                XSSFPicture pic = (XSSFPicture) shape;
                XSSFClientAnchor clientAnchor = (XSSFClientAnchor) anchor;
                if (clientAnchor.getRow1() < getHeaderRowNo()) {
                    for (int j = 0; j < pics.size(); j++) {
                        XSSFPictureData picture = pics.get(j);
                        if (picture.getPackagePart().getPartName()
                                .equals(pic.getPictureData().getPackagePart().getPartName())) {
                            drawingPatriarch.createPicture(clientAnchor, j);
                        }
                    }
                }
            }
        }
    }

    try {
        // set comments in the original sheet
        XSSFDrawing patriarch = sheet.getDrawingPatriarch();
        for (CellReference cell : errorMessages.keySet()) {
            if (cell != null && errorMessages.get(cell) != null) {
                XSSFComment comment = sheet.getCellComment(new CellAddress(cell.getRow(), cell.getCol()));
                boolean isNewComment = false;
                if (comment == null) {
                    XSSFClientAnchor anchor = factory.createClientAnchor();
                    anchor.setDx1(100);
                    anchor.setDx2(100);
                    anchor.setDy1(100);
                    anchor.setDy2(100);
                    anchor.setCol1(cell.getCol());
                    anchor.setCol2(cell.getCol() + 4);
                    anchor.setRow1(cell.getRow());
                    anchor.setRow2(cell.getRow() + 4);
                    anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);

                    comment = patriarch.createCellComment(anchor);
                    isNewComment = true;
                }
                XSSFRichTextString rts = factory.createRichTextString("OFBiz PriCat:\n");
                rts.applyFont(boldFont);
                rts.append(errorMessages.get(cell), plainFont);
                comment.setString(rts);
                comment.setAuthor("Apache OFBiz PriCat");
                if (isNewComment) {
                    sheet.getRow(cell.getRow()).getCell(cell.getCol()).setCellComment(comment);
                    OFBizPricatUtil.formatCommentShape(sheet, cell);
                }
            }
        }

        // set comments in the new error sheet
        XSSFDrawing errorPatriarch = errorSheet.getDrawingPatriarch();
        int newRowNum = getHeaderRowNo() + 1;
        Map<Integer, Integer> rowMapping = new HashMap<Integer, Integer>();
        for (CellReference cell : errorMessages.keySet()) {
            if (cell != null && errorMessages.get(cell) != null) {
                XSSFRow row = sheet.getRow(cell.getRow());
                Integer rowNum = Integer.valueOf(row.getRowNum());
                int errorRow = newRowNum;
                if (rowMapping.containsKey(rowNum)) {
                    errorRow = rowMapping.get(rowNum).intValue();
                } else {
                    XSSFRow newRow = errorSheet.getRow(errorRow);
                    if (newRow == null) {
                        newRow = errorSheet.createRow(errorRow);
                    }
                    rowMapping.put(rowNum, Integer.valueOf(errorRow));
                    newRow.setHeight(row.getHeight());
                    copyRow(row, newRow, factory, errorPatriarch);
                    newRowNum++;
                }
            }
        }

        // write to file
        if (sequenceNum > 0L) {
            File commentedExcel = FileUtil.getFile(tempFilesFolder + userLoginId + "/" + sequenceNum + ".xlsx");
            fos = new FileOutputStream(commentedExcel);
            workbook.write(fos);
        } else {
            fos = new FileOutputStream(pricatFile);
            workbook.write(fos);
        }
        fos.flush();
        fos.close();
        workbook.close();
    } catch (FileNotFoundException e) {
        report.println(e);
        Debug.logError(e, module);
    } catch (IOException e) {
        report.println(e);
        Debug.logError(e, module);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                Debug.logError(e, module);
            }
        }
        if (workbook != null) {
            try {
                workbook.close();
            } catch (IOException e) {
                Debug.logError(e, module);
            }
        }
    }
    report.println(UtilProperties.getMessage(resource, "ok", locale), InterfaceReport.FORMAT_OK);
    report.println();
}

From source file:org.azkfw.document.database.xlsx.XLSXWriter.java

License:Apache License

private XSSFWorkbook write(final DatabaseModel datasource) {
    workbook = new XSSFWorkbook();

    styleManager = new CellStyleManager(workbook);

    // ?/*from   w  w w  . j  ava 2  s . co m*/
    fontTitle = workbook.createFont();
    fontTitle.setBold(true);
    fontTitle.setItalic(true);
    fontTitle.setFontHeightInPoints((short) 12);
    fontLabel = workbook.createFont();
    fontLabel.setBold(true);
    fontLabel.setFontHeightInPoints((short) 9);
    fontValue = workbook.createFont();
    fontValue.setBold(false);
    fontValue.setFontHeightInPoints((short) 9);
    fontLink = workbook.createFont();
    fontLink.setUnderline(Font.U_SINGLE);
    fontLink.setColor(IndexedColors.BLUE.getIndex());
    fontLink.setFontHeightInPoints((short) 9);

    styleTitle = workbook.createCellStyle();
    styleTitle.setFont(fontTitle);
    /////////////////////////////////////////////////////////////////////
    XSSFFont fontPK = workbook.createFont();
    fontPK.setBold(true);
    fontPK.setItalic(true);
    fontPK.setFontHeightInPoints((short) 9);

    // Value
    defStyleHeadValue = workbook.createCellStyle();
    defStyleHeadValue.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleHeadValue.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleHeadValue.setFont(fontValue);
    defStyleHeadValue.setBorderTop(CellStyle.BORDER_THIN);
    defStyleHeadValue.setBorderBottom(CellStyle.BORDER_THIN);
    defStyleHeadValue.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleHeadValue.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleHeadValue);
    defStyleLabel = workbook.createCellStyle();
    defStyleLabel.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleLabel.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
    defStyleLabel.setFont(fontLabel);
    defStyleLabel.setBorderTop(CellStyle.BORDER_THIN);
    defStyleLabel.setBorderBottom(CellStyle.BORDER_THIN);
    defStyleLabel.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleLabel.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleLabel);
    // 
    defStyleListValue = workbook.createCellStyle();
    defStyleListValue.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleListValue.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleListValue.setFont(fontValue);
    defStyleListValue.setBorderTop(CellStyle.BORDER_DOTTED);
    defStyleListValue.setBorderBottom(CellStyle.BORDER_DOTTED);
    defStyleListValue.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleListValue.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleListValue);
    // 
    defStyleListValueNo = workbook.createCellStyle();
    defStyleListValueNo.setAlignment(CellStyle.ALIGN_RIGHT);
    defStyleListValueNo.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleListValueNo.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleListValueNo.setFont(fontValue);
    defStyleListValueNo.setBorderTop(CellStyle.BORDER_DOTTED);
    defStyleListValueNo.setBorderBottom(CellStyle.BORDER_DOTTED);
    defStyleListValueNo.setBorderLeft(BD_RECT);
    defStyleListValueNo.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleListValueNo);
    // Value(pk)
    defStyleListValuePK = workbook.createCellStyle();
    defStyleListValuePK.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleListValuePK.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleListValuePK.setFont(fontPK);
    defStyleListValuePK.setBorderTop(CellStyle.BORDER_DOTTED);
    defStyleListValuePK.setBorderBottom(CellStyle.BORDER_DOTTED);
    defStyleListValuePK.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleListValuePK.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleListValuePK);
    // Value(center)
    defStyleListValueCenter = workbook.createCellStyle();
    defStyleListValueCenter.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleListValueCenter.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleListValueCenter.setFont(fontValue);
    defStyleListValueCenter.setAlignment(CellStyle.ALIGN_CENTER);
    defStyleListValueCenter.setBorderTop(CellStyle.BORDER_DOTTED);
    defStyleListValueCenter.setBorderBottom(CellStyle.BORDER_DOTTED);
    defStyleListValueCenter.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleListValueCenter.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleListValueCenter);
    // Value(link)
    defStyleListValueLink = workbook.createCellStyle();
    defStyleListValueLink.setFillPattern(CellStyle.SOLID_FOREGROUND);
    defStyleListValueLink.setFillForegroundColor(IndexedColors.WHITE.getIndex());
    defStyleListValueLink.setFont(fontLink);
    defStyleListValueLink.setBorderTop(CellStyle.BORDER_DOTTED);
    defStyleListValueLink.setBorderBottom(CellStyle.BORDER_DOTTED);
    defStyleListValueLink.setBorderLeft(CellStyle.BORDER_THIN);
    defStyleListValueLink.setBorderRight(CellStyle.BORDER_THIN);
    styleManager.set(defStyleListValueLink);

    // ?
    workbook.createSheet(getTableListSheetName());
    for (TableModel table : datasource.getTables()) {
        workbook.createSheet(getTableSheetName(table.getName()));
    }

    // 
    createTableListSheet(datasource, workbook.getSheet(getTableListSheetName()));
    // 
    for (TableModel table : datasource.getTables()) {
        XSSFSheet sheet = workbook.getSheet(getTableSheetName(table.getName()));
        createTableSheet(datasource, table, sheet);
    }

    return workbook;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java

License:Open Source License

/**
 * Method used to initialize the different styles according to the type of value
 *///from  w  w w . ja  v a  2s  . c  o m
private void initializeStyles(int[] columnTypes) {

    // Style header
    styleHeader = (XSSFCellStyle) workbook.createCellStyle();
    styleHeader.setAlignment(CellStyle.ALIGN_CENTER);
    styleHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    styleHeader.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    styleHeader.setFillForegroundColor(new XSSFColor(Color.decode(HEADER_BG_COLOR_HEX)));
    styleHeader.setWrapText(true);

    // Font
    XSSFFont font = (XSSFFont) workbook.createFont();
    font.setBold(true);
    font.setFontName(HEADER_FONT_NAME);
    font.setColor(new XSSFColor(Color.decode(HEADER_FONT_COLOR_HEX)));
    font.setFontHeightInPoints(HEADER_FONT_SIZE);
    styleHeader.setFont(font);

    richTextFont = workbook.createFont();
    richTextFont.setFontName("Tahoma");
    richTextFont.setBold(true);
    richTextFont.setColor(HSSFColor.RED.index);

    // border
    this.setBottomBorderCell(styleHeader, Color.decode(HEADER_BORDER_COLOR_HEX));

    CreationHelper createHelper = workbook.getCreationHelper();

    columnStyles = new XSSFCellStyle[columnTypes.length];
    for (int c = 0; c < columnTypes.length; c++) {

        columnStyles[c] = (XSSFCellStyle) workbook.createCellStyle();
        switch (columnTypes[c]) {

        // Style numeric
        case COLUMN_TYPE_NUMERIC:
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            break;

        // Style date
        case COLUMN_TYPE_DATE:
            columnStyles[c].setDataFormat(createHelper.createDataFormat().getFormat(CELL_DATE_FORMAT));
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            break;

        // styleBoleean
        case COLUMN_TYPE_BOOLEAN:
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("#.##"));
            break;

        // styleBudget
        case COLUMN_TYPE_BUDGET:
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("$#,##0.00"));
            // "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"
            break;

        // Style decimal
        case COLUMN_TYPE_DECIMAL:
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            columnStyles[c].setDataFormat(workbook.createDataFormat().getFormat("#.##"));
            break;

        // Style long string
        case COLUMN_TYPE_TEXT_LONG:
            columnStyles[c].setAlignment(HorizontalAlignment.LEFT);
            columnStyles[c].setWrapText(true);
            break;

        // Style short string
        case COLUMN_TYPE_TEXT_SHORT:
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            break;

        // Style hyperlink
        case COLUMN_TYPE_HYPERLINK:
            XSSFFont hlinkfont = (XSSFFont) workbook.createFont();
            hlinkfont.setUnderline(XSSFFont.U_SINGLE);
            hlinkfont.setColor(HSSFColor.BLUE.index);
            columnStyles[c].setFont(hlinkfont);
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            break;

        // Style hyperlink
        case COLUMN_TYPE_DATE_TIME:
            columnStyles[c].setDataFormat(createHelper.createDataFormat().getFormat(CELL_DATE_TIME_FORMAT));
            columnStyles[c].setAlignment(CellStyle.ALIGN_CENTER);
            break;

        }
        this.setBottomBorderCell(columnStyles[c], Color.decode(CELL_BORDER_COLOR_HEX));
        if (c == 0) {
            columnStyles[c].setBorderLeft(CELL_BORDER_TYPE_LEFT);
            columnStyles[c].setBorderColor(BorderSide.LEFT, new XSSFColor(Color.decode(CELL_BORDER_COLOR_HEX)));
        } else if (c == columnTypes.length - 1) {
            columnStyles[c].setBorderRight(CELL_BORDER_TYPE_RIGHT);
            columnStyles[c].setBorderColor(BorderSide.RIGHT,
                    new XSSFColor(Color.decode(CELL_BORDER_COLOR_HEX)));
        }

    }

}

From source file:org.displaytag.render.XssfTableWriter.java

License:Artistic License

/**
 * @see org.displaytag.render.TableWriterTemplate#writeCaption(org.displaytag.model.TableModel)
 *//*from  w  w w . jav  a2s .  c om*/
protected void writeCaption(TableModel model) throws Exception {
    XSSFFont captionFont = wb.createFont();
    captionFont.setFontHeightInPoints((short) 14);
    captionFont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    captionFont.setBold(true);
    captionFont.setItalic(false);

    CellStyle captionstyle = this.wb.createCellStyle();
    captionstyle.setAlignment(CellStyle.ALIGN_CENTER);
    captionstyle.setFont(captionFont);

    this.colNum = 0;
    this.currentRow = this.sheet.createRow(this.rowNum++);
    this.currentCell = this.currentRow.createCell(this.colNum++);
    this.currentCell.setCellStyle(captionstyle);
    String caption = model.getCaption();
    this.currentCell.setCellValue(new XSSFRichTextString(caption));
    this.rowSpanTable(model);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportAuthorHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *//*from  w  w w . jav  a2 s  .  c o m*/
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();

    commonCellStyle = book.createCellStyle();
    commonCellStyle.setAlignment(HorizontalAlignment.LEFT);
    commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    noteCellStyle = book.createCellStyle();
    XSSFFont noteFont = book.createFont();
    noteFont.setFontHeightInPoints((short) 9);
    noteCellStyle.setFont(noteFont);
    noteCellStyle.setAlignment(HorizontalAlignment.LEFT);
    noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
    noteCellStyle.setWrapText(true);
}

From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportBookHelperImpl.java

License:Open Source License

/**
 * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
 *//*  ww  w.ja va  2  s.c  om*/
@Override
protected void prepare(XSSFWorkbook book) {
    flagCellStyle = book.createCellStyle();
    flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
    flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    idCellStyle = book.createCellStyle();
    XSSFFont idFont = book.createFont();
    idFont.setFontHeightInPoints((short) 9);
    idCellStyle.setFont(idFont);

    commonCellStyle = book.createCellStyle();
    commonCellStyle.setAlignment(HorizontalAlignment.LEFT);
    commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);

    dateCellStyle = book.createCellStyle();
    dateCellStyle.setAlignment(HorizontalAlignment.LEFT);
    dateCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
}