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

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

Introduction

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

Prototype

void cloneStyleFrom(CellStyle source);

Source Link

Document

Clones all the style information from another CellStyle, onto this one.

Usage

From source file:com.funtl.framework.smoke.core.commons.excel.ExportExcel.java

License:Apache License

/**
 * ?/*from w ww.  ja  v a2s  . c o  m*/
 *
 * @param row    
 * @param column ?
 * @param val    
 * @param align  ??1?23??
 * @return ?
 */
public Cell addCell(Row row, int column, Object val, int align, Class<?> fieldType) {
    Cell cell = row.createCell(column);
    String cellFormatString = "@";
    try {
        if (val == null) {
            cell.setCellValue("");
        } else if (fieldType != Class.class) {
            cell.setCellValue((String) fieldType.getMethod("setValue", Object.class).invoke(null, val));
        } else {
            if (val instanceof String) {
                cell.setCellValue((String) val);
            } else if (val instanceof Integer) {
                cell.setCellValue((Integer) val);
                cellFormatString = "0";
            } else if (val instanceof Long) {
                cell.setCellValue((Long) val);
                cellFormatString = "0";
            } else if (val instanceof Double) {
                cell.setCellValue((Double) val);
                cellFormatString = "0.00";
            } else if (val instanceof Float) {
                cell.setCellValue((Float) val);
                cellFormatString = "0.00";
            } else if (val instanceof Date) {
                cell.setCellValue((Date) val);
                cellFormatString = "yyyy-MM-dd HH:mm";
            } else {
                cell.setCellValue((String) Class
                        .forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
                                "fieldtype." + val.getClass().getSimpleName() + "Type"))
                        .getMethod("setValue", Object.class).invoke(null, val));
            }
        }
        if (val != null) {
            CellStyle style = styles.get("data_column_" + column);
            if (style == null) {
                style = wb.createCellStyle();
                style.cloneStyleFrom(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
                style.setDataFormat(wb.createDataFormat().getFormat(cellFormatString));
                styles.put("data_column_" + column, style);
            }
            cell.setCellStyle(style);
        }
    } catch (Exception ex) {
        log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString());
        cell.setCellValue(val.toString());
    }
    return cell;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.PostReviewQAReportGenerator.java

License:Apache License

private void writeQualityAssessmentInfo(Workbook p_workbook, Sheet p_sheet, Job p_job,
        GlobalSightLocale p_targetLocale) throws Exception {
    String qualityAssessment = null;
    int col = 1;/*  w w w . j a va  2s .  c  o  m*/
    int row = 6;
    CellStyle contentStyle = p_workbook.createCellStyle();
    contentStyle.cloneStyleFrom(getContentStyle(p_workbook));
    contentStyle.setBorderTop(CellStyle.BORDER_THIN);
    contentStyle.setBorderRight(CellStyle.BORDER_THIN);
    contentStyle.setBorderBottom(CellStyle.BORDER_THIN);
    contentStyle.setBorderLeft(CellStyle.BORDER_THIN);
    contentStyle.setLocked(false);
    Row langInfoRow = getRow(p_sheet, row);
    Cell qualityCell = getCell(langInfoRow, col++);
    for (Workflow wf : p_job.getWorkflows()) {
        if (p_targetLocale.getId() == wf.getTargetLocale().getId()) {
            Collection tasks = ServerProxy.getTaskManager().getCurrentTasks(wf.getId());
            if (tasks != null) {
                for (Iterator it = tasks.iterator(); it.hasNext();) {
                    Task task = (Task) it.next();
                    qualityAssessment = task.getQualityAssessment();
                }
            }
        }
    }
    if (qualityAssessment != null && !"".endsWith(qualityAssessment)) {
        qualityCell.setCellValue(qualityAssessment);
    } else {
        qualityCell.setCellValue("");
    }

    qualityCell.setCellStyle(contentStyle);

}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.PostReviewQAReportGenerator.java

License:Apache License

private void writeMarketSuitabilityInfo(Workbook p_workbook, Sheet p_sheet, Job p_job,
        GlobalSightLocale p_targetLocale) throws Exception {
    String marketSuitabilty = null;
    int col = 1;//from   w w  w.  j a v a 2 s.  c  om
    int row = 7;
    CellStyle contentStyle = p_workbook.createCellStyle();
    contentStyle.cloneStyleFrom(getContentStyle(p_workbook));
    contentStyle.setBorderTop(CellStyle.BORDER_THIN);
    contentStyle.setBorderRight(CellStyle.BORDER_THIN);
    contentStyle.setBorderBottom(CellStyle.BORDER_THIN);
    contentStyle.setBorderLeft(CellStyle.BORDER_THIN);
    contentStyle.setLocked(false);
    Row langInfoRow = getRow(p_sheet, row);
    Cell marketCell = getCell(langInfoRow, col++);
    for (Workflow wf : p_job.getWorkflows()) {
        if (p_targetLocale.getId() == wf.getTargetLocale().getId()) {
            Collection tasks = ServerProxy.getTaskManager().getCurrentTasks(wf.getId());
            if (tasks != null) {
                for (Iterator it = tasks.iterator(); it.hasNext();) {
                    Task task = (Task) it.next();
                    marketSuitabilty = task.getMarketSuitability();
                }
            }
        }
    }
    if (marketSuitabilty != null && !"".endsWith(marketSuitabilty)) {
        marketCell.setCellValue(marketSuitabilty);
    } else {
        marketCell.setCellValue("");
    }
    marketCell.setCellStyle(contentStyle);

}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.PostReviewQAReportGenerator.java

License:Apache License

private void writeReviewerComment(Workbook p_workbook, Sheet p_sheet) throws Exception {
    int col = 1;//from w  ww .jav a  2  s  . com
    int row = 8;
    CellStyle contentStyle = p_workbook.createCellStyle();
    contentStyle.cloneStyleFrom(getContentStyle(p_workbook));
    contentStyle.setBorderTop(CellStyle.BORDER_THIN);
    contentStyle.setBorderRight(CellStyle.BORDER_THIN);
    contentStyle.setBorderBottom(CellStyle.BORDER_THIN);
    contentStyle.setBorderLeft(CellStyle.BORDER_THIN);
    contentStyle.setLocked(false);
    Row langInfoRow = getRow(p_sheet, row);

    Cell commentCell = getCell(langInfoRow, col++);
    commentCell.setCellValue("");
    commentCell.setCellStyle(contentStyle);

}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.PostReviewQAReportGenerator.java

License:Apache License

/**
 * For Post-Review QA Report, Write segment information into each row of the
 * sheet.//from w  w w .java2 s. c  o m
 * 
 * @param p_sheet
 *            the sheet
 * @param p_jobId
 *            the job id
 * @param p_targetLang
 *            the target locale String
 * @param p_srcPageId
 *            the source page id
 * @param p_dateFormat
 *            the data format
 * @param p_row
 *            the segment row in sheet
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale,
        String p_srcPageId, String p_dateFormat, int p_row) throws Exception {
    boolean review_only = false;
    Vector<TargetPage> targetPages = new Vector<TargetPage>();

    TranslationMemoryProfile tmp = null;
    Vector<String> excludItems = null;
    for (Workflow workflow : p_job.getWorkflows()) {
        if (cancel)
            return 0;

        if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState())
        // || Workflow.EXPORT_FAILED.equals(workflow.getState())
                || Workflow.IMPORT_FAILED.equals(workflow.getState())) {
            continue;
        }
        if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) {
            targetPages = workflow.getTargetPages();
            tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile();
            if (tmp != null) {
                excludItems = tmp.getJobExcludeTuTypes();
            }
            Collection tasks = ServerProxy.getTaskManager().getCurrentTasks(workflow.getId());
            if (tasks != null) {
                for (Iterator it = tasks.iterator(); it.hasNext();) {
                    Task task = (Task) it.next();
                    review_only = task.isType(Task.TYPE_REVIEW);

                }
            }
        }
    }

    if (targetPages.isEmpty()) {
        // If no corresponding target page exists, set the cell blank
        writeBlank(p_sheet, p_row, 11);
    } else {
        LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager();
        TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager();

        Locale sourcePageLocale = p_job.getSourceLocale().getLocale();
        Locale targetPageLocale = p_targetLocale.getLocale();
        TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale,
                p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId()));
        Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null;
        if (termLeverageOptions != null) {
            termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(),
                    p_targetLocale);
        }

        String category = null;
        PseudoData pData = new PseudoData();
        pData.setMode(PseudoConstants.PSEUDO_COMPACT);
        String sid = null;
        Set<Integer> rowsWithCommentSet = new HashSet<Integer>();
        for (int i = 0; i < targetPages.size(); i++) {
            if (cancel)
                return 0;

            TargetPage targetPage = (TargetPage) targetPages.get(i);
            SourcePage sourcePage = targetPage.getSourcePage();

            if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) {
                // ignore the source pages not equal to the one
                // if the request comes from pop up editor
                continue;
            }

            SegmentTuUtil.getTusBySourcePageId(sourcePage.getId());
            List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage);
            List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage);

            MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics(
                    sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold());
            Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager
                    .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId()));
            Map<Long, Tuv> allTuvMap = this.getAllTuvsMap(targetPage);

            sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale();
            targetPageLocale = targetPage.getGlobalSightLocale().getLocale();

            boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString());
            boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString());

            // Find segment all comments belong to this target page
            Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId());

            for (int j = 0; j < targetTuvs.size(); j++) {
                if (cancel)
                    return 0;

                int col = 0;
                Tuv targetTuv = (Tuv) targetTuvs.get(j);
                Tuv sourceTuv = (Tuv) sourceTuvs.get(j);

                category = sourceTuv.getTu(p_job.getId()).getTuType();
                if (excludItems != null && excludItems.contains(category)) {
                    continue;
                }

                // Comment
                List<IssueHistory> issueHistories = null;
                String commentHistory = "";
                String failure = "";
                String commentStatus = "";
                String lastComment = "";
                String priority = "";
                Issue issue = issuesMap.get(targetTuv.getId());
                if (issue != null) {
                    issueHistories = issue.getHistory();
                    failure = issue.getCategory();
                    commentStatus = issue.getStatus();
                    priority = issue.getPriority();
                }
                if (issueHistories != null && issueHistories.size() > 0) {
                    for (IssueHistory issueHistory : issueHistories) {
                        commentHistory += issueHistory.getComment() + "\r";
                    }
                    lastComment = issueHistories.get(0).getComment();
                }

                sid = sourceTuv.getSid();

                StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems,
                        sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId());

                // Get Terminology/Glossary Source and Target.
                String sourceTerms = "";
                String targetTerms = "";
                if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) {
                    Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap
                            .get(sourceTuv.getId());
                    if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) {
                        TermLeverageMatch tlm = termLeverageMatchSet.iterator().next();
                        sourceTerms = tlm.getMatchedSourceTerm();
                        targetTerms = tlm.getMatchedTargetTerm();
                    }
                }

                Row currentRow = getRow(p_sheet, p_row);

                // Source segment with compact tags
                CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_A = getCell(currentRow, col);
                cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId()));
                cell_A.setCellStyle(srcStyle);
                col++;

                // Target segment with compact tags
                CellStyle trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                String previousSegments = getPreviousSegments(allTuvMap, targetTuv.getId(), targetTuv,
                        p_job.getId(), pData);
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(previousSegments);
                cell_B.setCellStyle(trgStyle);
                col++;

                // Modify the translation
                CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook)
                        : getUnlockedStyle(p_workBook);
                modifyTranslationStyle.setLocked(false);
                Cell cell_C = getCell(currentRow, col);
                cell_C.setCellValue(getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId()));
                if (review_only) {
                    modifyTranslationStyle.setLocked(true);
                }
                cell_C.setCellStyle(modifyTranslationStyle);
                col++;

                // Reviewers Comments
                Cell cell_D = getCell(currentRow, col);
                cell_D.setCellValue(commentHistory);
                cell_D.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Category failure
                Cell cell_E = getCell(currentRow, col);
                cell_E.setCellValue(failure);
                cell_E.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Comment Status
                Cell cell_F = getCell(currentRow, col);
                cell_F.setCellValue(commentStatus);
                CellStyle commentCS = p_workBook.createCellStyle();
                commentCS.cloneStyleFrom(getContentStyle(p_workBook));
                //                    commentCS.setLocked(false);
                cell_F.setCellStyle(commentCS);
                // add comment status drop down list for current row.
                String[] statusArray = getCommentStatusList(lastComment);
                if (statusArray.length > 1) {
                    rowsWithCommentSet.add(p_row);
                }
                col++;

                // Priority
                Cell cell_G = getCell(currentRow, col);
                cell_G.setCellValue(priority);
                cell_G.setCellStyle(getContentStyle(p_workBook));
                col++;

                // TM match
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue(matches.toString());
                cell_H.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary source
                Cell cell_I = getCell(currentRow, col);
                cell_I.setCellValue(sourceTerms);
                cell_I.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary target
                Cell cell_J = getCell(currentRow, col);
                cell_J.setCellValue(targetTerms);
                cell_J.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Job Id
                Cell cell_K = getCell(currentRow, col);
                cell_K.setCellValue(p_job.getId());
                cell_K.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Segment id
                Cell cell_L = getCell(currentRow, col);
                cell_L.setCellValue(sourceTuv.getTu(p_job.getId()).getId());
                cell_L.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Fix for GBS-1484
                String externalPageId = sourcePage.getExternalPageId();
                String[] pathNames = externalPageId.split("\\\\");
                String name = pathNames[pathNames.length - 1];
                boolean temp = pathNames[0].contains(")");
                if (temp) {
                    String[] firstNames = pathNames[0].split("\\)");
                    String detailName = firstNames[0];
                    name = name + detailName + ")";
                }
                // Page Name
                Cell cell_M = getCell(currentRow, col);
                cell_M.setCellValue(name);
                cell_M.setCellStyle(getContentStyle(p_workBook));
                col++;

                // SID
                Cell cell_N = getCell(currentRow, col);
                cell_N.setCellValue(sid);
                cell_N.setCellStyle(getContentStyle(p_workBook));
                col++;

                p_row++;
            }
        }
        // Add comment status
        addCommentStatus(p_sheet, rowsWithCommentSet, p_row);
        // Add category failure drop down list here.
        addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN,
                CATEGORY_FAILURE_COLUMN);
        addPriority(p_sheet, SEGMENT_START_ROW, p_row - 1, PRIORITY_COLUMN, PRIORITY_COLUMN);
    }

    return p_row;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java

License:Apache License

/**
 * For Translations Edit Report, Write segment information into each row of
 * the sheet.// w w w.j a va 2 s.  c  om
 * 
 * @param p_sheet
 *            the sheet
 * @param p_jobId
 *            the job id
 * @param p_targetLang
 *            the target locale String
 * @param p_srcPageId
 *            the source page id
 * @param p_dateFormat
 *            the data format
 * @param p_row
 *            the segment row in sheet
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale,
        String p_srcPageId, String p_dateFormat, int p_row) throws Exception {
    Vector<TargetPage> targetPages = new Vector<TargetPage>();

    TranslationMemoryProfile tmp = null;
    Vector<String> excludItems = null;

    for (Workflow workflow : p_job.getWorkflows()) {
        if (cancel)
            return 0;

        if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState())
        // || Workflow.EXPORT_FAILED.equals(workflow.getState())
                || Workflow.IMPORT_FAILED.equals(workflow.getState())) {
            continue;
        }
        if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) {
            targetPages = workflow.getTargetPages();
            tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile();
            if (tmp != null) {
                excludItems = tmp.getJobExcludeTuTypes();
            }
        }
    }

    if (targetPages.isEmpty()) {
        // If no corresponding target page exists, set the cell blank
        writeBlank(p_sheet, p_row, 11);
    } else {
        LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager();
        TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager();

        Locale sourcePageLocale = p_job.getSourceLocale().getLocale();
        Locale targetPageLocale = p_targetLocale.getLocale();
        TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale,
                p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId()));
        Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null;
        if (termLeverageOptions != null) {
            termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(),
                    p_targetLocale);
        }

        String category = null;
        PseudoData pData = new PseudoData();
        pData.setMode(PseudoConstants.PSEUDO_COMPACT);
        String sid = null;
        Set<Integer> rowsWithCommentSet = new HashSet<Integer>();
        for (int i = 0; i < targetPages.size(); i++) {
            if (cancel)
                return 0;

            TargetPage targetPage = (TargetPage) targetPages.get(i);
            SourcePage sourcePage = targetPage.getSourcePage();

            if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) {
                // ignore the source pages not equal to the one
                // if the request comes from pop up editor
                continue;
            }

            SegmentTuUtil.getTusBySourcePageId(sourcePage.getId());
            List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage);
            List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage);

            MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics(
                    sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold());
            Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager
                    .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId()));

            sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale();
            targetPageLocale = targetPage.getGlobalSightLocale().getLocale();

            boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString());
            boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString());

            // Find segment all comments belong to this target page
            Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId());

            for (int j = 0; j < targetTuvs.size(); j++) {
                if (cancel)
                    return 0;

                int col = 0;
                Tuv targetTuv = (Tuv) targetTuvs.get(j);
                Tuv sourceTuv = (Tuv) sourceTuvs.get(j);

                category = sourceTuv.getTu(p_job.getId()).getTuType();
                if (excludItems != null && excludItems.contains(category)) {
                    continue;
                }

                // Comment
                List issueHistories = null;
                String lastComment = "";
                String failure = "";
                String commentStatus = "";
                Issue issue = issuesMap.get(targetTuv.getId());
                if (issue != null) {
                    issueHistories = issue.getHistory();
                    failure = issue.getCategory();
                    commentStatus = issue.getStatus();
                }
                if (issueHistories != null && issueHistories.size() > 0) {
                    IssueHistory issueHistory = (IssueHistory) issueHistories.get(0);
                    lastComment = issueHistory.getComment();
                }

                sid = sourceTuv.getSid();

                StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems,
                        sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId());

                // Get Terminology/Glossary Source and Target.
                String sourceTerms = "";
                String targetTerms = "";
                if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) {
                    Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap
                            .get(sourceTuv.getId());
                    if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) {
                        TermLeverageMatch tlm = termLeverageMatchSet.iterator().next();
                        sourceTerms = tlm.getMatchedSourceTerm();
                        targetTerms = tlm.getMatchedTargetTerm();
                    }
                }

                Row currentRow = getRow(p_sheet, p_row);

                // Source segment with compact tags
                CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_A = getCell(currentRow, col);
                cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId()));
                cell_A.setCellStyle(srcStyle);
                col++;

                // Target segment with compact tags
                CellStyle trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId()));
                cell_B.setCellStyle(trgStyle);
                col++;

                // Modify the translation
                CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook)
                        : getUnlockedStyle(p_workBook);
                Cell cell_C = getCell(currentRow, col);
                cell_C.setCellValue("");
                cell_C.setCellStyle(modifyTranslationStyle);
                col++;

                //Reviewers Comments
                Cell cell_D = getCell(currentRow, col);
                cell_D.setCellValue(lastComment);
                cell_D.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Translators Comments
                Cell cell_E = getCell(currentRow, col);
                cell_E.setCellValue("");
                cell_E.setCellStyle(getUnlockedStyle(p_workBook));
                col++;

                // Category failure
                Cell cell_F = getCell(currentRow, col);
                cell_F.setCellValue(failure);
                cell_F.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Comment Status
                Cell cell_G = getCell(currentRow, col);
                cell_G.setCellValue(commentStatus);
                CellStyle commentCS = p_workBook.createCellStyle();
                commentCS.cloneStyleFrom(getContentStyle(p_workBook));
                commentCS.setLocked(false);
                cell_G.setCellStyle(commentCS);
                // add comment status drop down list for current row.
                String[] statusArray = getCommentStatusList(lastComment);
                if (statusArray.length > 1) {
                    rowsWithCommentSet.add(p_row);
                }
                col++;

                // TM match
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue(matches.toString());
                cell_H.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary source
                Cell cell_I = getCell(currentRow, col);
                cell_I.setCellValue(sourceTerms);
                cell_I.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary target
                Cell cell_J = getCell(currentRow, col);
                cell_J.setCellValue(targetTerms);
                cell_J.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Job Id
                Cell cell_K = getCell(currentRow, col);
                cell_K.setCellValue(p_job.getId());
                cell_K.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Segment id
                Cell cell_L = getCell(currentRow, col);
                cell_L.setCellValue(sourceTuv.getTu(p_job.getId()).getId());
                cell_L.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Fix for GBS-1484
                String externalPageId = sourcePage.getExternalPageId();
                String[] pathNames = externalPageId.split("\\\\");
                String name = pathNames[pathNames.length - 1];
                boolean temp = pathNames[0].contains(")");
                if (temp) {
                    String[] firstNames = pathNames[0].split("\\)");
                    String detailName = firstNames[0];
                    name = name + detailName + ")";
                }
                //Page Name
                Cell cell_M = getCell(currentRow, col);
                cell_M.setCellValue(name);
                cell_M.setCellStyle(getContentStyle(p_workBook));
                col++;

                // SID
                Cell cell_N = getCell(currentRow, col);
                cell_N.setCellValue(sid);
                cell_N.setCellStyle(getContentStyle(p_workBook));
                col++;

                p_row++;
            }
        }
        //Add comment status
        addCommentStatus(p_sheet, rowsWithCommentSet, p_row);
        // Add category failure drop down list here.
        addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN,
                CATEGORY_FAILURE_COLUMN);
    }

    return p_row;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationVerificationReportGenerator.java

License:Apache License

/**
 * For Translations Edit Report, Write segment information into each row of
 * the sheet.// ww w .j a va 2 s  .  c o  m
 * 
 * @param p_sheet
 *            the sheet
 * @param p_jobId
 *            the job id
 * @param p_targetLang
 *            the target locale String
 * @param p_srcPageId
 *            the source page id
 * @param p_dateFormat
 *            the data format
 * @param p_row
 *            the segment row in sheet
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale,
        String p_srcPageId, String p_dateFormat, int p_row) throws Exception {
    Vector<TargetPage> targetPages = new Vector<TargetPage>();

    TranslationMemoryProfile tmp = null;
    Vector<String> excludItems = null;

    for (Workflow workflow : p_job.getWorkflows()) {
        if (cancel)
            return 0;

        if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState())
        // || Workflow.EXPORT_FAILED.equals(workflow.getState())
                || Workflow.IMPORT_FAILED.equals(workflow.getState())) {
            continue;
        }
        if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) {
            targetPages = workflow.getTargetPages();
            tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile();
            if (tmp != null) {
                excludItems = tmp.getJobExcludeTuTypes();
            }
        }
    }

    if (targetPages.isEmpty()) {
        // If no corresponding target page exists, set the cell blank
        writeBlank(p_sheet, p_row, 11);
    } else {
        LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager();
        TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager();

        Locale sourcePageLocale = p_job.getSourceLocale().getLocale();
        Locale targetPageLocale = p_targetLocale.getLocale();
        TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale,
                p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId()));
        Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null;
        if (termLeverageOptions != null) {
            termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(),
                    p_targetLocale);
        }

        String category = null;
        PseudoData pData = new PseudoData();
        pData.setMode(PseudoConstants.PSEUDO_COMPACT);
        String sid = null;
        Set<Integer> rowsWithCommentSet = new HashSet<Integer>();
        for (int i = 0; i < targetPages.size(); i++) {
            if (cancel)
                return 0;

            TargetPage targetPage = (TargetPage) targetPages.get(i);
            SourcePage sourcePage = targetPage.getSourcePage();

            if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) {
                // ignore the source pages not equal to the one
                // if the request comes from pop up editor
                continue;
            }

            SegmentTuUtil.getTusBySourcePageId(sourcePage.getId());
            List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage);
            List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage);

            MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics(
                    sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold());
            Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager
                    .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId()));
            Map<Long, Tuv> allTuvMap = this.getAllTuvsMap(targetPage);

            sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale();
            targetPageLocale = targetPage.getGlobalSightLocale().getLocale();

            boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString());
            boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString());

            // Find segment all comments belong to this target page
            Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId());

            for (int j = 0; j < targetTuvs.size(); j++) {
                if (cancel)
                    return 0;

                int col = 0;
                Tuv targetTuv = (Tuv) targetTuvs.get(j);
                Tuv sourceTuv = (Tuv) sourceTuvs.get(j);

                category = sourceTuv.getTu(p_job.getId()).getTuType();
                if (excludItems != null && excludItems.contains(category)) {
                    continue;
                }

                // Comment
                List issueHistories = null;
                String lastComment = "";
                String failure = "";
                String commentStatus = "";
                Issue issue = issuesMap.get(targetTuv.getId());
                if (issue != null) {
                    issueHistories = issue.getHistory();
                    failure = issue.getCategory();
                    commentStatus = issue.getStatus();
                }
                if (issueHistories != null && issueHistories.size() > 0) {
                    IssueHistory issueHistory = (IssueHistory) issueHistories.get(0);
                    lastComment = issueHistory.getComment();
                }

                sid = sourceTuv.getSid();

                StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems,
                        sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId());

                // Get Terminology/Glossary Source and Target.
                String sourceTerms = "";
                String targetTerms = "";
                if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) {
                    Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap
                            .get(sourceTuv.getId());
                    if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) {
                        TermLeverageMatch tlm = termLeverageMatchSet.iterator().next();
                        sourceTerms = tlm.getMatchedSourceTerm();
                        targetTerms = tlm.getMatchedTargetTerm();
                    }
                }

                Row currentRow = getRow(p_sheet, p_row);

                // Source segment with compact tags
                CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_A = getCell(currentRow, col);
                cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId()));
                cell_A.setCellStyle(srcStyle);
                col++;

                // the translation after the translation activity
                CellStyle trgStyle = null;
                String previousSegments = getPreviousSegments(allTuvMap, targetTuv.getId(), targetTuv,
                        p_job.getId(), pData);
                String currentSegments = getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId());
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(previousSegments);
                if (StringUtil.isNotEmpty(previousSegments) && !previousSegments.endsWith(currentSegments)) {
                    trgStyle = m_rtlTargetLocale ? getRtlContentStyle1(p_workBook)
                            : getContentStyle1(p_workBook);
                } else {
                    trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook);
                }
                cell_B.setCellStyle(trgStyle);
                col++;

                // the translation after the review activity
                // CellStyle trgStyle = m_rtlTargetLocale ?
                // getRtlContentStyle(p_workBook)
                // : getContentStyle(p_workBook);
                Cell cell_C = getCell(currentRow, col);
                cell_C.setCellValue(currentSegments);
                cell_C.setCellStyle(trgStyle);
                col++;

                // Modify the translation
                CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook)
                        : getUnlockedStyle(p_workBook);
                Cell cell_D = getCell(currentRow, col);
                cell_D.setCellValue("");
                cell_D.setCellStyle(modifyTranslationStyle);
                col++;

                // Reviewers Comments
                Cell cell_E = getCell(currentRow, col);
                cell_E.setCellValue(lastComment);
                cell_E.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Translators Comments
                Cell cell_F = getCell(currentRow, col);
                cell_F.setCellValue("");
                cell_F.setCellStyle(getUnlockedStyle(p_workBook));
                col++;

                // Category failure
                Cell cell_G = getCell(currentRow, col);
                cell_G.setCellValue(failure);
                cell_G.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Comment Status
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue(commentStatus);
                CellStyle commentCS = p_workBook.createCellStyle();
                commentCS.cloneStyleFrom(getContentStyle(p_workBook));
                commentCS.setLocked(false);
                cell_H.setCellStyle(commentCS);
                // add comment status drop down list for current row.
                String[] statusArray = getCommentStatusList(lastComment);
                if (statusArray.length > 1) {
                    rowsWithCommentSet.add(p_row);
                }
                col++;

                // TM match
                Cell cell_I = getCell(currentRow, col);
                cell_I.setCellValue(matches.toString());
                cell_I.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary source
                Cell cell_J = getCell(currentRow, col);
                cell_J.setCellValue(sourceTerms);
                cell_J.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary target
                Cell cell_K = getCell(currentRow, col);
                cell_K.setCellValue(targetTerms);
                cell_K.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Job Id
                Cell cell_L = getCell(currentRow, col);
                cell_L.setCellValue(p_job.getId());
                cell_L.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Segment id
                Cell cell_M = getCell(currentRow, col);
                cell_M.setCellValue(sourceTuv.getTu(p_job.getId()).getId());
                cell_M.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Fix for GBS-1484
                String externalPageId = sourcePage.getExternalPageId();
                String[] pathNames = externalPageId.split("\\\\");
                String name = pathNames[pathNames.length - 1];
                boolean temp = pathNames[0].contains(")");
                if (temp) {
                    String[] firstNames = pathNames[0].split("\\)");
                    String detailName = firstNames[0];
                    name = name + detailName + ")";
                }
                // Page Name
                Cell cell_N = getCell(currentRow, col);
                cell_N.setCellValue(name);
                cell_N.setCellStyle(getContentStyle(p_workBook));
                col++;

                // SID
                Cell cell_O = getCell(currentRow, col);
                cell_O.setCellValue(sid);
                cell_O.setCellStyle(getContentStyle(p_workBook));
                col++;

                p_row++;
            }
        }
        // Add comment status
        addCommentStatus(p_sheet, rowsWithCommentSet, p_row);
        // Add category failure drop down list here.
        addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN,
                CATEGORY_FAILURE_COLUMN);
    }

    return p_row;
}

From source file:com.griffinslogistics.document.excel.BDLGenerator.java

private static Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;//from w  ww.j  a v  a  2s.c o m
    Font titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 26);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("title", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("pulsioName", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("contacts", style);

    CellStyle footerStyle = workbook.createCellStyle();
    Font footerFont = workbook.createFont();
    footerFont.setFontHeightInPoints((short) 14);
    footerFont.setFontName("Calibri");
    footerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    footerStyle.setFont(footerFont);
    footerStyle.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("footer", footerStyle);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setItalic(true);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);

    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setBorderLeft(CellStyle.BORDER_MEDIUM);
    style.setBorderTop(CellStyle.BORDER_MEDIUM);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderBottom(CellStyle.BORDER_THIN);

    styles.put("tableHeadersLeft", style);

    CellStyle headerRowMiddleCellStyle = workbook.createCellStyle();
    headerRowMiddleCellStyle.cloneStyleFrom(style);
    headerRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableHeadersMiddle", headerRowMiddleCellStyle);

    CellStyle headerRowRightCellStyle = workbook.createCellStyle();
    headerRowRightCellStyle.cloneStyleFrom(style);
    headerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableHeadersRight", headerRowRightCellStyle);

    CellStyle footerRowRightCellStyle = workbook.createCellStyle();
    footerRowRightCellStyle.cloneStyleFrom(style);
    footerRowRightCellStyle.setFillPattern(CellStyle.NO_FILL);
    footerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    footerRowRightCellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);

    styles.put("tableFooters", footerRowRightCellStyle);

    CellStyle bodyRowLeftCellStyle = workbook.createCellStyle();
    bodyRowLeftCellStyle.cloneStyleFrom(style);
    Font titleBodyFont = workbook.createFont();
    titleBodyFont.setFontHeightInPoints((short) 14);
    titleBodyFont.setFontName("Calibri");
    bodyRowLeftCellStyle.setFont(titleBodyFont);
    bodyRowLeftCellStyle.setBorderTop(CellStyle.BORDER_THIN);
    bodyRowLeftCellStyle.setFillPattern(CellStyle.NO_FILL);

    styles.put("tableBodyLeft", bodyRowLeftCellStyle);

    CellStyle bodyRowMiddleCellStyle = workbook.createCellStyle();
    bodyRowMiddleCellStyle.cloneStyleFrom(bodyRowLeftCellStyle);
    bodyRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableBodyMiddle", bodyRowMiddleCellStyle);

    CellStyle bodyRowRightCellStyle = workbook.createCellStyle();
    bodyRowRightCellStyle.cloneStyleFrom(bodyRowMiddleCellStyle);
    bodyRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableBodyRight", bodyRowRightCellStyle);

    return styles;
}

From source file:com.griffinslogistics.document.excel.CMRGenerator.java

private static Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

    CellStyle style = workbook.createCellStyle();
    Font font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    styles.put(DEFAULT_STYLE, style);/*from www  . j av a 2  s  .  c om*/

    CellStyle labelStyle = workbook.createCellStyle();
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setColor(HSSFColor.DARK_RED.index);
    labelStyle.setFont(font);
    labelStyle.setWrapText(true);
    styles.put(LABEL_STYLE, labelStyle);

    CellStyle labelTopStyle = workbook.createCellStyle();
    labelTopStyle.cloneStyleFrom(labelStyle);
    labelTopStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelTopStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_TOP_STYLE, labelTopStyle);

    CellStyle labelMiddleStyle = workbook.createCellStyle();
    labelMiddleStyle.cloneStyleFrom(labelStyle);
    labelMiddleStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelMiddleStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelMiddleStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_MIDDLE_STYLE, labelMiddleStyle);

    CellStyle labelLeftStyle = workbook.createCellStyle();
    labelLeftStyle.cloneStyleFrom(labelStyle);
    labelLeftStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelLeftStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_LEFT_STYLE, labelLeftStyle);

    CellStyle labelRightStyle = workbook.createCellStyle();
    labelRightStyle.cloneStyleFrom(labelStyle);
    labelRightStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelRightStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_RIGHT_STYLE, labelRightStyle);

    CellStyle labelBottomStyle = workbook.createCellStyle();
    labelBottomStyle.cloneStyleFrom(labelStyle);
    labelBottomStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelBottomStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelBottomStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    styles.put(LABEL_BOTTOM_STYLE, labelBottomStyle);

    CellStyle labelWholeStyle = workbook.createCellStyle();
    labelWholeStyle.cloneStyleFrom(labelStyle);
    labelWholeStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setBorderTop(CellStyle.BORDER_MEDIUM);
    labelWholeStyle.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    styles.put(LABEL_WHOLE_STYLE, labelWholeStyle);

    Font contentFont = workbook.createFont();
    contentFont.setFontHeightInPoints((short) 12);
    contentFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

    CellStyle contentTopStyle = workbook.createCellStyle();
    contentTopStyle.cloneStyleFrom(labelTopStyle);
    contentTopStyle.setFont(contentFont);
    styles.put(CONTENT_TOP_STYLE, contentTopStyle);

    CellStyle contentMiddleStyle = workbook.createCellStyle();
    contentMiddleStyle.cloneStyleFrom(labelMiddleStyle);
    contentMiddleStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_STYLE, contentMiddleStyle);

    CellStyle contentMiddleAllignRightStyle = workbook.createCellStyle();
    contentMiddleAllignRightStyle.cloneStyleFrom(contentMiddleStyle);
    contentMiddleAllignRightStyle.setBorderRight(CellStyle.BORDER_NONE);
    contentMiddleAllignRightStyle.setFont(contentFont);
    contentMiddleAllignRightStyle.setAlignment(CellStyle.ALIGN_RIGHT);
    styles.put(CONTENT_MIDDLE_ALLIGN_RIGHT_STYLE, contentMiddleAllignRightStyle);

    CellStyle contentBottomAllignCenterStyle = workbook.createCellStyle();
    contentBottomAllignCenterStyle.cloneStyleFrom(contentMiddleStyle);
    contentBottomAllignCenterStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    contentBottomAllignCenterStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);
    contentBottomAllignCenterStyle.setFont(contentFont);
    contentBottomAllignCenterStyle.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put(CONTENT_BOTTOM_ALLIGN_CENTER_STYLE, contentBottomAllignCenterStyle);

    CellStyle contentMiddleNoBordersAllignRightStyle = workbook.createCellStyle();
    contentMiddleNoBordersAllignRightStyle.cloneStyleFrom(contentMiddleAllignRightStyle);
    contentMiddleNoBordersAllignRightStyle.setBorderLeft(CellStyle.BORDER_NONE);
    contentMiddleNoBordersAllignRightStyle.setAlignment(CellStyle.ALIGN_CENTER);
    contentMiddleNoBordersAllignRightStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_NO_BORDERS_STYLE, contentMiddleNoBordersAllignRightStyle);

    CellStyle contentMiddleAllignCenterStyle = workbook.createCellStyle();
    contentMiddleAllignCenterStyle.cloneStyleFrom(contentMiddleStyle);
    contentMiddleAllignCenterStyle.setAlignment(CellStyle.ALIGN_CENTER);
    contentMiddleAllignCenterStyle.setFont(contentFont);
    styles.put(CONTENT_MIDDLE_ALLIGN_CENTER_STYLE, contentMiddleAllignCenterStyle);

    CellStyle contentRightStyle = workbook.createCellStyle();
    contentRightStyle.cloneStyleFrom(labelRightStyle);
    contentRightStyle.setFont(contentFont);
    styles.put(CONTENT_RIGHT_STYLE, contentRightStyle);

    CellStyle contentBottomStyle = workbook.createCellStyle();
    contentBottomStyle.cloneStyleFrom(labelBottomStyle);
    contentBottomStyle.setFont(contentFont);
    styles.put(CONTENT_BOTTOM_STYLE, contentBottomStyle);

    CellStyle contentWholeStyle = workbook.createCellStyle();
    contentWholeStyle.cloneStyleFrom(labelWholeStyle);
    contentWholeStyle.setFont(contentFont);
    styles.put(CONTENT_WHOLE_STYLE, contentWholeStyle);

    return styles;
}

From source file:com.griffinslogistics.excel.BDLGenerator.java

private static Map<String, CellStyle> createStyles(Workbook workbook) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*from   w  w w. j  a v a  2s . com*/
    Font titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 26);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    styles.put("title", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 18);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("pulsioName", style);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("contacts", style);

    CellStyle footerStyle = workbook.createCellStyle();
    Font footerFont = workbook.createFont();
    footerFont.setFontHeightInPoints((short) 14);
    footerFont.setFontName("Calibri");
    footerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    footerStyle.setFont(footerFont);
    footerStyle.setAlignment(CellStyle.ALIGN_JUSTIFY);

    styles.put("footer", footerStyle);

    titleFont = workbook.createFont();
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setFontName("Calibri");
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setItalic(true);
    style = workbook.createCellStyle();
    style.setFont(titleFont);
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setWrapText(true);

    // Override 25% grey to lighter grey
    HSSFWorkbook hssfWorkbook = (HSSFWorkbook) workbook;
    HSSFPalette palette = hssfWorkbook.getCustomPalette();
    palette.setColorAtIndex(HSSFColor.GREY_25_PERCENT.index, (byte) 242, //RGB red (0-255)
            (byte) 242, //RGB green
            (byte) 242 //RGB blue
    );

    style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setBorderLeft(CellStyle.BORDER_MEDIUM);
    style.setBorderTop(CellStyle.BORDER_MEDIUM);
    style.setBorderRight(CellStyle.BORDER_THIN);
    style.setBorderBottom(CellStyle.BORDER_THIN);

    styles.put("tableHeadersLeft", style);

    CellStyle headerRowMiddleCellStyle = workbook.createCellStyle();
    headerRowMiddleCellStyle.cloneStyleFrom(style);
    headerRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableHeadersMiddle", headerRowMiddleCellStyle);

    CellStyle headerRowRightCellStyle = workbook.createCellStyle();
    headerRowRightCellStyle.cloneStyleFrom(style);
    headerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableHeadersRight", headerRowRightCellStyle);

    CellStyle footerRowRightCellStyle = workbook.createCellStyle();
    footerRowRightCellStyle.cloneStyleFrom(style);
    footerRowRightCellStyle.setFillPattern(CellStyle.NO_FILL);
    footerRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);
    footerRowRightCellStyle.setBorderBottom(CellStyle.BORDER_MEDIUM);

    styles.put("tableFooters", footerRowRightCellStyle);

    CellStyle bodyRowLeftCellStyle = workbook.createCellStyle();
    bodyRowLeftCellStyle.cloneStyleFrom(style);
    Font titleBodyFont = workbook.createFont();
    titleBodyFont.setFontHeightInPoints((short) 14);
    titleBodyFont.setFontName("Calibri");
    bodyRowLeftCellStyle.setFont(titleBodyFont);
    bodyRowLeftCellStyle.setBorderTop(CellStyle.BORDER_THIN);
    bodyRowLeftCellStyle.setFillPattern(CellStyle.NO_FILL);

    styles.put("tableBodyLeft", bodyRowLeftCellStyle);

    CellStyle bodyRowMiddleCellStyle = workbook.createCellStyle();
    bodyRowMiddleCellStyle.cloneStyleFrom(bodyRowLeftCellStyle);
    bodyRowMiddleCellStyle.setBorderLeft(CellStyle.BORDER_THIN);

    styles.put("tableBodyMiddle", bodyRowMiddleCellStyle);

    CellStyle bodyRowRightCellStyle = workbook.createCellStyle();
    bodyRowRightCellStyle.cloneStyleFrom(bodyRowMiddleCellStyle);
    bodyRowRightCellStyle.setBorderRight(CellStyle.BORDER_MEDIUM);

    styles.put("tableBodyRight", bodyRowRightCellStyle);

    return styles;
}