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

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

Introduction

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

Prototype

public void setBold(boolean bold) 

Source Link

Document

set a boolean value for the boldness to use.

Usage

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

License:Open Source License

private static int createTitle(XSSFWorkbook workbook, XSSFSheet worksheet, Service service) {

    XSSFCellStyle titleStyle = workbook.createCellStyle();
    titleStyle.setAlignment(HorizontalAlignment.CENTER);
    titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);

    XSSFFont txtFont = workbook.createFont();
    txtFont.setFontName("calibri");
    txtFont.setFontHeightInPoints((short) 11);
    txtFont.setBold(true);
    titleStyle.setFont(txtFont);/*from w  w  w .ja  v a 2  s .  co m*/

    XSSFRow row = worksheet.createRow(0);

    XSSFCell cell = row.createCell(0);
    cell.setCellValue(
            "Inventaire " + service.getDirection().getLibelleCourt() + " - " + service.getLibelleCourt());
    cell.setCellStyle(titleStyle);

    worksheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    return 2;
}

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

License:Open Source License

private static int generateHeader(XSSFSheet worksheet, XSSFWorkbook workbook, int rowNum) {
    // Now add//from   w  ww . ja v  a  2 s  .  com
    XSSFRow row = worksheet.createRow(rowNum);
    XSSFCell cell;

    XSSFCellStyle headerStyle = workbook.createCellStyle();
    headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.index);
    headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    headerStyle.setBorderBottom(BorderStyle.MEDIUM);
    headerStyle.setBorderLeft(BorderStyle.MEDIUM);
    headerStyle.setBorderRight(BorderStyle.MEDIUM);
    headerStyle.setBorderTop(BorderStyle.MEDIUM);
    headerStyle.setAlignment(HorizontalAlignment.CENTER);
    headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);

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

    cell = row.createCell(0);
    cell.setCellValue("Photo");
    cell.setCellStyle(headerStyle);
    worksheet.setColumnWidth(0, ConvertImageUnits.pixel2WidthUnits(COLUMN_WIDTH_PX));//4387

    cell = row.createCell(1);
    cell.setCellValue("Rfrence");
    cell.setCellStyle(headerStyle);

    cell = row.createCell(2);
    cell.setCellValue("Libell");
    cell.setCellStyle(headerStyle);

    cell = row.createCell(3);
    cell.setCellValue("Stock\n Appock");
    cell.setCellStyle(headerStyle);
    cell.getCellStyle().setWrapText(true);

    cell = row.createCell(4);
    cell.setCellValue("Stock\n rel");
    cell.setCellStyle(headerStyle);
    cell.getCellStyle().setWrapText(true);

    row.setHeight((short) 600);

    return rowNum + 1;
}

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;/*  w ww . j  av  a 2 s . co  m*/
    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 {//from   w  ww .  j av a  2s . c  om
            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.apache.fineract.accounting.closure.storeglaccountbalance.service.GLClosureJournalEntryBalanceReadPlatformServiceImpl.java

License:Apache License

/**
 * Create the excel file with the balance report data
 * //www  .ja v  a  2  s  . c o 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();// w  ww .  ja va 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.doclet.jaxrs.writer.JAXRSXlsxDocletWriter.java

License:Apache License

private void printSheet(final XSSFWorkbook wb, final XSSFSheet sheet, final List<APIModel> apis) {

    XSSFCell cell = null;/* w ww  .j av a  2s .  c om*/
    XSSFRow row = null;

    ////////////////////////////////////////////////////
    XSSFFont fontBold = wb.createFont();
    fontBold.setBold(true);

    CellStyle styleHeader = wb.createCellStyle();
    styleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
    styleHeader.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
    styleHeader.setFont(fontBold);
    styleHeader.setBorderTop(CellStyle.BORDER_THIN);
    styleHeader.setBorderLeft(CellStyle.BORDER_THIN);
    styleHeader.setBorderRight(CellStyle.BORDER_THIN);
    styleHeader.setBorderBottom(CellStyle.BORDER_DOUBLE);

    row = sheet.createRow(0); //////////////////////////
    cell = row.createCell(1, Cell.CELL_TYPE_STRING);

    CellStyle style1 = wb.createCellStyle();
    style1.setFont(fontBold);
    cell.setCellStyle(style1);
    cell.setCellValue("I/F (API) ");

    row = sheet.createRow(1); //////////////////////////
    cell = row.createCell(1, Cell.CELL_TYPE_STRING);
    cell.setCellValue("API???");

    row = sheet.createRow(4); //////////////////////////
    cell = row.createCell(1, Cell.CELL_TYPE_STRING);
    cell.setCellValue("ID");
    cell.setCellStyle(styleHeader);
    cell = row.createCell(2, Cell.CELL_TYPE_STRING);
    cell.setCellValue("Group");
    cell.setCellStyle(styleHeader);
    cell = row.createCell(3, Cell.CELL_TYPE_STRING);
    cell.setCellValue("Name");
    cell.setCellStyle(styleHeader);
    cell = row.createCell(4, Cell.CELL_TYPE_STRING);
    cell.setCellValue("Comment");
    cell.setCellStyle(styleHeader);

    int offsetRow = 5;
    int offsetCol = 1;
    for (int i = 0; i < apis.size(); i++) {
        APIModel api = apis.get(i);

        row = sheet.createRow(offsetRow + i);

        cell = row.createCell(offsetCol + 0, Cell.CELL_TYPE_STRING);
        cell.setCellValue(s(api.getId()));

        cell = row.createCell(offsetCol + 2, Cell.CELL_TYPE_STRING);
        cell.setCellValue(s(api.getName()));

        cell = row.createCell(offsetCol + 3, Cell.CELL_TYPE_STRING);
        cell.setCellValue(s(api.getComment()));
    }
}

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);

    // ?//  w  ww  . ja va  2  s .  c o  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   ww  w. j a v a  2 s. c om
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)
 *///  w  w w  .  j av  a 2  s .  c  o  m
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);
}