Example usage for org.apache.poi.ss.usermodel Cell setCellStyle

List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle

Introduction

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

Prototype

void setCellStyle(CellStyle style);

Source Link

Document

Set the style for the cell.

Usage

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

/**
 * Add hidden info "DITA_taskID" for offline uploading. When upload, system
 * can know the report type and current task ID report generated from.
 *//*from  www  . java 2  s . c o m*/
private void addHidenInfoForUpload(Workbook p_workbook, Sheet p_sheet, long p_taskId) throws Exception {
    Row titleRow = getRow(p_sheet, 0);
    Cell cell_AA1 = getCell(titleRow, 26);
    cell_AA1.setCellValue("DITA_" + p_taskId);
    cell_AA1.setCellStyle(contentStyle);

    p_sheet.setColumnHidden(26, true);
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

private void addSegmentHeader(Workbook p_workBook, Sheet p_sheet) throws Exception {
    int col = 0;//from ww  w.  j a v  a  2  s . c o  m
    int row = SEGMENT_HEADER_ROW;
    Row segHeaderRow = getRow(p_sheet, row);

    // Description
    Cell cell_A = getCell(segHeaderRow, col);
    cell_A.setCellValue(m_bundle.getString("lb_description"));
    cell_A.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    // Page name
    Cell cell_B = getCell(segHeaderRow, col);
    cell_B.setCellValue(m_bundle.getString("lb_page_name"));
    cell_B.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    // Job id
    Cell cell_C = getCell(segHeaderRow, col);
    cell_C.setCellValue(m_bundle.getString("lb_job_id_report"));
    cell_C.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    // Segment Id
    Cell cell_D = getCell(segHeaderRow, col);
    cell_D.setCellValue(m_bundle.getString("lb_segment_id"));
    cell_D.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    // Source Segment
    Cell cell_E = getCell(segHeaderRow, col);
    cell_E.setCellValue(m_bundle.getString("lb_source_segment"));
    cell_E.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    // Target Segment
    Cell cell_F = getCell(segHeaderRow, col);
    cell_F.setCellValue(m_bundle.getString("lb_target_segment"));
    cell_F.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    // False Positive
    Cell cell_G = getCell(segHeaderRow, col);
    cell_G.setCellValue(m_bundle.getString("lb_false_positive"));
    cell_G.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 20 * 256);
    col++;

    Cell cell_H = getCell(segHeaderRow, col);
    cell_H.setCellValue(m_bundle.getString("lb_comments"));
    cell_H.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;
}

From source file:com.globalsight.everest.qachecks.DITAQAChecker.java

License:Apache License

@SuppressWarnings("rawtypes")
private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Task p_task) throws Exception {
    int row = SEGMENT_START_ROW;
    Job job = ServerProxy.getJobHandler().getJobById(p_task.getJobId());
    GlobalSightLocale trgLocale = p_task.getTargetLocale();

    Vector<TargetPage> targetPages = new Vector<TargetPage>();

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

    for (Workflow workflow : job.getWorkflows()) {
        if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState())
        //                    || Workflow.EXPORT_FAILED.equals(workflow.getState())
                || Workflow.IMPORT_FAILED.equals(workflow.getState())) {
            continue;
        }// ww  w .j  av a  2s.co m
        if (trgLocale.getId() == workflow.getTargetLocale().getId()) {
            targetPages = workflow.getTargetPages();
            tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile();
            if (tmp != null) {
                excludItems = tmp.getJobExcludeTuTypes();
            }
        }
    }

    List<SourcePage> nonDitaPages = new ArrayList<SourcePage>();
    if (targetPages.isEmpty()) {
        // If no corresponding target page exists, set the cell blank
        writeBlank(p_sheet, row, 11);
    } else {
        Locale sourcePageLocale = p_task.getSourceLocale().getLocale();
        Locale targetPageLocale = trgLocale.getLocale();
        String tuType = null;
        PseudoData pData = new PseudoData();
        pData.setMode(PseudoConstants.PSEUDO_VERBOSE);
        for (int i = 0; i < targetPages.size(); i++) {
            TargetPage targetPage = (TargetPage) targetPages.get(i);
            SourcePage sourcePage = targetPage.getSourcePage();
            String externalPageId = sourcePage.getExternalPageId().replace("\\", "/");
            if (!externalPageId.toLowerCase().endsWith(".xml")) {
                nonDitaPages.add(sourcePage);
                continue;
            }

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

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

            for (int j = 0; j < targetTuvs.size(); j++) {
                int col = 0;
                Tuv sourceTuv = (Tuv) sourceTuvs.get(j);
                Tuv targetTuv = (Tuv) targetTuvs.get(j);

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

                String source = getSegment(pData, sourceTuv, m_rtlSourceLocale, job.getId());
                String target = getSegment(pData, targetTuv, m_rtlTargetLocale, job.getId());
                Object[] checkResults = doDitaCheck(source, target, trgLocale);

                Row currentRow = getRow(p_sheet, row);

                // Description
                Cell cell_A = getCell(currentRow, col);
                cell_A.setCellStyle(getContentStyle(p_workBook));
                cell_A.setCellValue("");
                // set the description message
                if (checkResults != null && checkResults.length == 3) {
                    cell_A.setCellValue((String) checkResults[0]);
                }
                col++;

                //Page Name
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(externalPageId);
                cell_B.setCellStyle(getNoWrapContentStyle(p_workBook));
                col++;

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

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

                // Source segment
                CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_E = getCell(currentRow, col);
                cell_E.setCellStyle(srcStyle);
                List<String> srcHighlightIndexes = getHighlightIndexes(checkResults, "source");
                // DITA check failed
                if (srcHighlightIndexes != null) {
                    RichTextString ts = getRichTextString(p_workBook, source, srcHighlightIndexes);
                    cell_E.setCellType(XSSFCell.CELL_TYPE_STRING);
                    cell_E.setCellValue(ts);
                } else {
                    cell_E.setCellValue(source);
                }
                col++;

                // Target segment
                CellStyle trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_F = getCell(currentRow, col);
                cell_F.setCellStyle(trgStyle);
                List<String> trgHighlightIndexes = getHighlightIndexes(checkResults, "target");
                // DITA check failed
                if (trgHighlightIndexes != null) {
                    RichTextString ts = getRichTextString(p_workBook, target, trgHighlightIndexes);
                    cell_F.setCellType(XSSFCell.CELL_TYPE_STRING);
                    cell_F.setCellValue(ts);
                } else {
                    cell_F.setCellValue(target);
                }
                col++;

                // False Positive
                Cell cell_G = getCell(currentRow, col);
                cell_G.setCellValue("No");
                cell_G.setCellStyle(getUnlockedStyle(p_workBook));
                col++;

                // Category failure
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue("");
                cell_H.setCellStyle(getUnlockedStyle(p_workBook));
                col++;

                row++;
            }
        }

        // Add category failure drop down list here.
        if (row > SEGMENT_START_ROW) {
            addFalsePositiveValidation(p_sheet, SEGMENT_START_ROW, row - 1, FALSE_POSITIVE_COLUMN,
                    FALSE_POSITIVE_COLUMN);
        }
    }

    row++;
    if (nonDitaPages.size() > 0) {
        for (SourcePage sp : nonDitaPages) {
            Row currentRow = getRow(p_sheet, row);
            Cell cell = getCell(currentRow, 0);
            cell.setCellStyle(getNoWrapContentStyle(p_workBook));
            String spName = sp.getExternalPageId().replace("\\", "/");
            cell.setCellValue("\"" + spName + "\" need not do DITA QA checks as it is not XML file.");
            row++;
        }
    }

    return row;
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void fillCells(Workbook p_workbook, Row p_currentRow, Workflow p_workflow, long p_jobId,
        boolean p_rtlSourceLocale, boolean p_rtlTargetLocale, SourcePage p_sourcePage, Tuv p_sourceTuv,
        String p_sourceSegment, String p_targetSegment, String p_desc) {
    int col = 0;/*from   w ww . j  a  v  a  2  s .c  om*/

    // Description
    Cell descCell = getCell(p_currentRow, col);
    descCell.setCellValue(p_desc);
    descCell.setCellStyle(getContentStyle(p_workbook));
    col++;

    // Page Name
    StringBuilder sb = new StringBuilder();
    sb.append(AmbFileStoragePathUtils.getCxeDocDir(p_workflow.getCompanyId()));
    sb.append(File.separator);
    sb.append(SourcePage.filtSpecialFile(p_sourcePage.getExternalPageId()));

    Cell pageNameCell = getCell(p_currentRow, col);
    pageNameCell.setCellValue(sb.toString());
    pageNameCell.setCellStyle(getContentStyle(p_workbook));
    col++;

    // Job ID
    Cell jobIdCell = getCell(p_currentRow, col);
    jobIdCell.setCellValue(p_jobId);
    jobIdCell.setCellStyle(getContentStyle(p_workbook));
    col++;

    // Segment ID
    Cell segmentIdCell = getCell(p_currentRow, col);
    segmentIdCell.setCellValue(p_sourceTuv.getTu(p_jobId).getId());
    segmentIdCell.setCellStyle(getContentStyle(p_workbook));
    col++;

    // Source segment with compact tags
    CellStyle srcStyle = p_rtlSourceLocale ? getRtlContentStyle(p_workbook) : getContentStyle(p_workbook);
    Cell sourceCell = getCell(p_currentRow, col);
    sourceCell.setCellValue(p_sourceSegment);
    sourceCell.setCellStyle(srcStyle);
    col++;

    // Target segment with compact tags
    CellStyle trgStyle = p_rtlTargetLocale ? getRtlContentStyle(p_workbook) : getContentStyle(p_workbook);
    Cell targetCell = getCell(p_currentRow, col);
    targetCell.setCellValue(p_targetSegment);
    targetCell.setCellStyle(trgStyle);
    col++;

    // False Positive
    Cell falsePositiveCell = getCell(p_currentRow, col);
    falsePositiveCell.setCellValue(FALSE_POSITIVE_NO);
    falsePositiveCell.setCellStyle(getUnlockedStyle(p_workbook));
    col++;

    // User Comments
    Cell commentsCell = getCell(p_currentRow, col);
    commentsCell.setCellValue("");
    commentsCell.setCellStyle(getUnlockedStyle(p_workbook));
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void addSegmentHeader(Workbook p_workbook, Sheet p_sheet) {
    int row = ROW_SEGMENT_HEADER;
    int col = 0;/*from  w w  w .  j a v a2  s .  c o  m*/
    Row segHeaderRow = getRow(p_sheet, row);

    Cell descCell = getCell(segHeaderRow, col);
    descCell.setCellValue(m_bundle.getString("lb_report_qa_report_description"));
    descCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 30 * 256);
    col++;

    Cell pageNamecell = getCell(segHeaderRow, col);
    pageNamecell.setCellValue(m_bundle.getString("lb_report_qa_report_page_name"));
    pageNamecell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 30 * 256);
    col++;

    Cell jobIdCell = getCell(segHeaderRow, col);
    jobIdCell.setCellValue(m_bundle.getString("lb_report_qa_report_job_id"));
    jobIdCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 12 * 256);
    col++;

    Cell segmentIdCell = getCell(segHeaderRow, col);
    segmentIdCell.setCellValue(m_bundle.getString("lb_report_qa_report_segment_id"));
    segmentIdCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 12 * 256);
    col++;

    Cell sourceCell = getCell(segHeaderRow, col);
    sourceCell.setCellValue(m_bundle.getString("lb_report_qa_report_source"));
    sourceCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell targetCell = getCell(segHeaderRow, col);
    targetCell.setCellValue(m_bundle.getString("lb_report_qa_report_target"));
    targetCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell falsePositiveCell = getCell(segHeaderRow, col);
    falsePositiveCell.setCellValue(m_bundle.getString("lb_report_qa_report_false_positive"));
    falsePositiveCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    Cell commentsCell = getCell(segHeaderRow, col);
    commentsCell.setCellValue(m_bundle.getString("lb_report_qa_report_comments"));
    commentsCell.setCellStyle(getHeaderStyle(p_workbook));
    p_sheet.setColumnWidth(col, 40 * 256);
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void addLanguageHeader(Workbook p_workbook, Sheet p_sheet) {
    int row = ROW_LANGUAGE_HEADER;
    int col = 0;//from   w  ww  .ja va  2  s.c o  m

    Row langRow = getRow(p_sheet, row);
    Cell srcLangCell = getCell(langRow, col);
    srcLangCell.setCellValue(m_bundle.getString("lb_report_qa_report_source_language"));
    srcLangCell.setCellStyle(getHeaderStyle(p_workbook));
    col++;

    Cell trgLangCell = getCell(langRow, col);
    trgLangCell.setCellValue(m_bundle.getString("lb_report_qa_report_target_language"));
    trgLangCell.setCellStyle(getHeaderStyle(p_workbook));
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void writeLanguageInfo(Workbook p_workbook, Sheet p_sheet, String p_sourceLang, String p_targetLang)
        throws Exception {
    int row = ROW_LANGUAGE_INFO;
    int col = 0;//from w w  w.  j av  a2 s  .co  m

    Row langInfoRow = getRow(p_sheet, row);

    Cell srcLangCell = getCell(langInfoRow, col++);
    srcLangCell.setCellValue(p_sourceLang);
    srcLangCell.setCellStyle(getContentStyle(p_workbook));

    Cell trgLangCell = getCell(langInfoRow, col++);
    trgLangCell.setCellValue(p_targetLang);
    trgLangCell.setCellStyle(getContentStyle(p_workbook));
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void addHiddenInfoForUpload(Workbook p_workbook, Sheet p_sheet, long p_taskId) {
    int hiddenColumn = COLUMN_HIDDEN_INFO;
    String hiddenValue = ReportConstants.PREFIX_QA_CHECKS_REPORT + "_" + p_taskId;
    Row titleRow = getRow(p_sheet, 0);/* www  .j a v  a  2 s.c o  m*/
    Cell hiddenCell = getCell(titleRow, hiddenColumn);
    hiddenCell.setCellValue(hiddenValue);
    hiddenCell.setCellStyle(getContentStyle(p_workbook));

    p_sheet.setColumnHidden(hiddenColumn, true);
}

From source file:com.globalsight.everest.qachecks.QAChecker.java

License:Apache License

private void addTitle(Workbook p_workbook, Sheet p_sheet) {
    Row titleRow = getRow(p_sheet, 0);/*w  ww.  j  a  v a  2s. c om*/
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(m_bundle.getString("lb_report_qa_report_title"));
    titleCell.setCellStyle(getTitleStyle(p_workbook));
}

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

License:Apache License

private void addTitle(Workbook p_workbook, Sheet p_sheet, String sheetTitle) throws Exception {
    // title font is black bold on white
    Font titleFont = p_workbook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle titileCs = p_workbook.createCellStyle();
    titileCs.setWrapText(false);/*  w  w  w .  ja  v  a  2 s  .c om*/
    titileCs.setFont(titleFont);

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(sheetTitle);
    titleCell.setCellStyle(titileCs);
    p_sheet.setColumnWidth(0, 22 * 256);
}