Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

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

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

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

License:Apache License

private CellStyle getUnlockedRightStyle(Workbook p_workbook) {
    if (unlockedRightStyle == null) {
        Font font = p_workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 10);

        CellStyle style = p_workbook.createCellStyle();
        style.setFont(font);//ww w .  j  a  v  a 2 s . c o m
        style.setLocked(false);
        style.setWrapText(true);
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
        style.setBorderTop(CellStyle.BORDER_THIN);
        style.setBorderRight(CellStyle.BORDER_THIN);
        style.setBorderBottom(CellStyle.BORDER_THIN);
        style.setBorderLeft(CellStyle.BORDER_THIN);
        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

        unlockedRightStyle = style;
    }

    return unlockedRightStyle;
}

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

License:Apache License

private CellStyle getEqual5Style(Workbook p_workbook) {
    if (equal5Style == null) {
        Font font = p_workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 9);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);//w w  w .  j a  v  a2 s  .  com
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);
        cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

        equal5Style = cs;
    }

    return equal5Style;
}

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

License:Apache License

private CellStyle getUnder5Style(Workbook p_workbook) {
    if (under5Style == null) {
        Font font = p_workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 9);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);//  w w  w  .j  a  va  2  s  .  c om
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.LIME.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);
        cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

        under5Style = cs;
    }

    return under5Style;
}

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

License:Apache License

private CellStyle getUnder4Style(Workbook p_workbook) {
    if (under4Style == null) {
        Font font = p_workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 9);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);/*from ww w . j a  v  a2 s. co  m*/
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);
        cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

        under4Style = cs;
    }

    return under4Style;
}

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

License:Apache License

private CellStyle getUnder3Style(Workbook p_workbook) {
    if (under3Style == null) {
        Font font = p_workbook.createFont();
        font.setColor(IndexedColors.BLACK.getIndex());
        font.setUnderline(Font.U_NONE);
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 9);

        CellStyle cs = p_workbook.createCellStyle();
        cs.setFont(font);/*  ww  w .ja  v a 2 s . c o  m*/
        cs.setWrapText(true);
        cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
        cs.setFillForegroundColor(IndexedColors.ROSE.getIndex());
        cs.setBorderTop(CellStyle.BORDER_THIN);
        cs.setBorderRight(CellStyle.BORDER_THIN);
        cs.setBorderBottom(CellStyle.BORDER_THIN);
        cs.setBorderLeft(CellStyle.BORDER_THIN);
        cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);

        under3Style = cs;
    }

    return under3Style;
}

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

License:Apache License

private CellStyle getHeaderStyle(Workbook p_workbook, Short top, Short right, Short bottom, Short left) {
    Font headerFont = p_workbook.createFont();
    headerFont.setColor(IndexedColors.BLACK.getIndex());
    headerFont.setUnderline(Font.U_NONE);
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 9);

    CellStyle cs = p_workbook.createCellStyle();
    cs.setFont(headerFont);/*from  w w w  . j a  v a 2  s .c o  m*/
    cs.setWrapText(true);
    if (top != null) {
        cs.setBorderTop(top);
    }
    if (right != null) {
        cs.setBorderRight(right);
    }
    if (bottom != null) {
        cs.setBorderBottom(bottom);
    }
    if (left != null) {
        cs.setBorderLeft(left);
    }

    return cs;
}

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

License:Apache License

private CellStyle getCommonHeaderStyle(Workbook p_workbook) {
    Font headerFont = p_workbook.createFont();
    headerFont.setColor(IndexedColors.BLACK.getIndex());
    headerFont.setUnderline(Font.U_NONE);
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 9);

    CellStyle cs = p_workbook.createCellStyle();
    cs.setFont(headerFont);//from  w ww  .  ja  v  a2s .c om
    cs.setWrapText(true);
    cs.setBorderTop(CellStyle.BORDER_THIN);
    cs.setBorderRight(CellStyle.BORDER_THIN);
    cs.setBorderBottom(CellStyle.BORDER_THIN);
    cs.setBorderLeft(CellStyle.BORDER_THIN);
    return cs;
}

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

License:Apache License

/**
 * Add title to the sheet//w w  w . j av  a2  s .c om
 * 
 * @param p_workBook
 * @param p_sheet
 *            the sheet
 * @throws Exception
 */
private void addTitle(Workbook p_workBook, Sheet p_sheet) throws Exception {
    Font titleFont = p_workBook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle cs = p_workBook.createCellStyle();
    cs.setFont(titleFont);

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(m_bundle.getString("lb_translation_edit_report"));
    titleCell.setCellStyle(cs);
}

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.//from  www .  ja  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()));

            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

/**
 * Add title to the sheet//from ww  w . j  a v  a2 s .  c  o  m
 * 
 * @param p_workBook
 * @param p_sheet
 *            the sheet
 * @throws Exception
 */
private void addTitle(Workbook p_workBook, Sheet p_sheet) throws Exception {
    Font titleFont = p_workBook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle cs = p_workBook.createCellStyle();
    cs.setFont(titleFont);

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(m_bundle.getString("lb_translation_verification_report"));
    titleCell.setCellStyle(cs);
}