Example usage for org.apache.poi.ss.usermodel Sheet getLastRowNum

List of usage examples for org.apache.poi.ss.usermodel Sheet getLastRowNum

Introduction

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

Prototype

int getLastRowNum();

Source Link

Document

Gets the last row on the sheet Note: rows which had content before and were set to empty later might still be counted as rows by Excel and Apache POI, so the result of this method will include such rows and thus the returned value might be higher than expected!

Usage

From source file:com.github.jaydsolanki.excelio.ExcelIO.java

private List<List<String>> readSheet(Sheet sheet) {
    List<List<String>> data = new ArrayList<>();
    for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
        Row row = sheet.getRow(i);/*from w  w w .j  a  va 2s. c  om*/
        List<String> rowList = new ArrayList<String>();
        for (int j = 0; j < row.getLastCellNum(); j++) {
            rowList.add(row.getCell(j) + "");
        }
        data.add(rowList);
    }
    return data;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadTERReportData(Sheet sheet, Task task, GlobalSightLocale tLocale) throws RemoteException {
    int segmentStartRow = ImplementedCommentsCheckReportGenerator.SEGMENT_START_ROW;
    Set<String> jobIds = new HashSet<String>();

    segId2RequiredTranslation = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2Comment = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();

    String segmentId = null;/*from   w  w  w  .j av  a  2 s .co  m*/
    long segIdLong;
    String updatedText = null;
    String jobIdText = null;
    String comment = null;
    String requiredComment = null;
    String commentStatus = null;
    boolean hasSegmentIdErro = false;

    int n = 5;
    int m = LOAD_DATA - n;

    for (int j = segmentStartRow, row = sheet.getLastRowNum(); j <= row; j++) {
        if (cancel)
            return null;

        int x = j * m / row;
        updateProcess(n + x);

        segmentId = ExcelUtil.getCellValue(sheet, j, 11);
        if (StringUtil.isEmpty(segmentId)) {
            break;
        }
        segIdLong = new Long(Long.parseLong(segmentId));

        updatedText = ExcelUtil.getCellValue(sheet, j, 2);
        comment = ExcelUtil.getCellValue(sheet, j, 3);
        requiredComment = ExcelUtil.getCellValue(sheet, j, 4);
        commentStatus = ExcelUtil.getCellValue(sheet, j, 6);

        if (EditUtil.isRTLLocale(tLocale))
            updatedText = EditUtil.removeU200F(updatedText);

        jobIdText = ExcelUtil.getCellValue(sheet, j, 10);
        jobIds.add(jobIdText);
        if (segmentId != null && !segmentId.equals("")) {
            if (updatedText != null && !updatedText.equals("")) {
                segId2RequiredTranslation.put(segIdLong, updatedText);
            }
            if (comment != null && !comment.equals("")) {
                if (requiredComment != null && !requiredComment.equals("")
                        && !StringUtil.equalsIgnoreSpace(requiredComment, "")) {
                    segId2Comment.put(segIdLong, requiredComment);
                }
                segId2CommentStatus.put(segIdLong, commentStatus);
            } else {
                if (requiredComment != null && !requiredComment.equals("")
                        && !StringUtil.equalsIgnoreSpace(requiredComment, "")) {
                    segId2Comment.put(segIdLong, requiredComment);
                    segId2CommentStatus.put(segIdLong, "query");
                }
            }
        } else {
            m_errWriter.addFileErrorMsg("Segment id is lost in row " + (j + 1) + "\r\n");
            hasSegmentIdErro = true;
        }
    }

    if (hasSegmentIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may hava changed some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadRCRSimpleReportDataAfter855(Sheet sheet, Task task, GlobalSightLocale tLocale,
        ResourceBundle bundle) throws RemoteException {
    int segmentStartRow = ReviewersCommentsReportGenerator.SEGMENT_START_ROW;
    Set<String> jobIds = new HashSet<String>();

    segId2Comment = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();
    String segmentId = null;//from  w ww .ja  v a 2 s.  c  om
    String pageId = null;
    String reviewerComment = null;
    Long segIdLong = null;
    String jobIdText = null;
    String failureType = null;
    String commentStatus = null;
    boolean hasIdErro = false;
    for (int k = segmentStartRow, row = sheet.getLastRowNum(); k <= row; k++) {
        if (cancel)
            return null;

        segmentId = ExcelUtil.getCellValue(sheet, k, 8);
        if (segmentId == null || segmentId.trim().length() == 0) {
            break;
        }
        jobIdText = ExcelUtil.getCellValue(sheet, k, 7);
        jobIds.add(jobIdText);
        long currentJobId = Long.parseLong(jobIdText);
        segIdLong = new Long(Long.parseLong(segmentId));
        Tu tu = ServerProxy.getTuvManager().getTuForSegmentEditor(segIdLong, currentJobId);
        TuImpl tuImpl = (TuImpl) tu;
        Tuv tuv = tuImpl.getTuv(reportTargetLocaleId, currentJobId);
        TuvImpl tuvImpl = (TuvImpl) tuv;
        TargetPage targetPage = tuvImpl.getTargetPage(currentJobId);
        pageId = new String(String.valueOf(targetPage.getId()));

        reviewerComment = ExcelUtil.getCellValue(sheet, k, 2);
        if (EditUtil.isRTLLocale(tLocale))
            reviewerComment = EditUtil.removeU200F(reviewerComment);

        failureType = ExcelUtil.getCellValue(sheet, k, 3);
        commentStatus = "";

        if (StringUtil.isNotEmpty(reviewerComment) || checkCommentStatus(sheet, k)) {
            if (segmentId != null && !segmentId.equals("") && pageId != null && !pageId.equals("")) {
                segId2PageId.put(segIdLong, new Long(Long.parseLong(pageId)));
                segId2Comment.put(segIdLong, reviewerComment);
                segId2FailureType.put(segIdLong, failureType);
                segId2CommentStatus.put(segIdLong, commentStatus);
            } else {
                m_errWriter.addFileErrorMsg("Segment or Page id is lost in row " + (k + 1) + "\r\n");
                hasIdErro = true;
            }

        }
    }
    if (hasIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may change some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadRCRSimpleReportDataFor855(Sheet sheet, Task task, GlobalSightLocale tLocale,
        ResourceBundle bundle) throws RemoteException {
    int segmentStartRow = ReviewersCommentsReportGenerator.SEGMENT_START_ROW;
    Set<String> jobIds = new HashSet<String>();

    segId2Comment = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();
    String segmentId = null;//from   w w w  .  j  ava  2s  .com
    String pageId = null;
    String reviewerComment = null;
    Long segIdLong = null;
    String jobIdText = null;
    String failureType = null;
    String commentStatus = null;
    boolean hasIdErro = false;
    for (int k = segmentStartRow, row = sheet.getLastRowNum(); k <= row; k++) {
        if (cancel)
            return null;

        segmentId = ExcelUtil.getCellValue(sheet, k, 7);
        if (segmentId == null || segmentId.trim().length() == 0) {
            break;
        }

        jobIdText = ExcelUtil.getCellValue(sheet, k, 6);
        jobIds.add(jobIdText);
        long currentJobId = Long.parseLong(jobIdText);
        segIdLong = new Long(Long.parseLong(segmentId));
        Tu tu = ServerProxy.getTuvManager().getTuForSegmentEditor(segIdLong, currentJobId);
        TuImpl tuImpl = (TuImpl) tu;
        Tuv tuv = tuImpl.getTuv(reportTargetLocaleId, currentJobId);
        TuvImpl tuvImpl = (TuvImpl) tuv;
        TargetPage targetPage = tuvImpl.getTargetPage(currentJobId);
        pageId = new String(String.valueOf(targetPage.getId()));

        reviewerComment = ExcelUtil.getCellValue(sheet, k, 2);
        if (EditUtil.isRTLLocale(tLocale))
            reviewerComment = EditUtil.removeU200F(reviewerComment);

        failureType = "";
        commentStatus = "";

        if (StringUtil.isNotEmpty(reviewerComment) || checkCommentStatus(sheet, k)) {
            if (segmentId != null && !segmentId.equals("") && pageId != null && !pageId.equals("")) {
                segId2PageId.put(segIdLong, new Long(Long.parseLong(pageId)));
                segId2Comment.put(segIdLong, reviewerComment);
                segId2FailureType.put(segIdLong, failureType);
                segId2CommentStatus.put(segIdLong, commentStatus);
            } else {
                m_errWriter.addFileErrorMsg("Segment or Page id is lost in row " + (k + 1) + "\r\n");
                hasIdErro = true;
            }

        }
    }
    if (hasIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may change some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadRCRReportData(Sheet sheet, Task task, GlobalSightLocale tLocale, ResourceBundle bundle)
        throws RemoteException {
    int segmentStartRow = ReviewersCommentsReportGenerator.SEGMENT_START_ROW;
    Set<String> jobIds = new HashSet<String>();

    segId2Comment = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();
    String segmentId = null;/*from   w w w  . j a  v  a  2s  .  c  o  m*/
    String pageId = null;
    String reviewerComment = null;
    Long segIdLong = null;
    String jobIdText = null;
    String failureType = null;
    String commentStatus = null;
    boolean hasIdErro = false;
    for (int k = segmentStartRow, row = sheet.getLastRowNum(); k <= row; k++) {
        if (cancel)
            return null;

        segmentId = ExcelUtil.getCellValue(sheet, k, 10);
        if (segmentId == null || segmentId.trim().length() == 0) {
            break;
        }

        jobIdText = ExcelUtil.getCellValue(sheet, k, 9);
        jobIds.add(jobIdText);
        long curJobId = Long.parseLong(jobIdText);
        segIdLong = new Long(Long.parseLong(segmentId));
        Tu tu = ServerProxy.getTuvManager().getTuForSegmentEditor(segIdLong, curJobId);
        TuImpl tuImpl = (TuImpl) tu;
        Tuv tuv = tuImpl.getTuv(reportTargetLocaleId, curJobId);
        TuvImpl tuvImpl = (TuvImpl) tuv;
        TargetPage targetPage = tuvImpl.getTargetPage(curJobId);
        pageId = new String(String.valueOf(targetPage.getId()));

        reviewerComment = ExcelUtil.getCellValue(sheet, k, 3);
        if (EditUtil.isRTLLocale(tLocale))
            reviewerComment = EditUtil.removeU200F(reviewerComment);

        failureType = ExcelUtil.getCellValue(sheet, k, 4);
        commentStatus = ExcelUtil.getCellValue(sheet, k, 5);

        if (StringUtil.isNotEmpty(reviewerComment) || checkCommentStatus(sheet, k)) {
            if (segmentId != null && !segmentId.equals("") && pageId != null && !pageId.equals("")) {
                segId2PageId.put(segIdLong, new Long(Long.parseLong(pageId)));
                segId2Comment.put(segIdLong, reviewerComment);
                segId2FailureType.put(segIdLong, failureType);
                segId2CommentStatus.put(segIdLong, commentStatus);
            } else {
                m_errWriter.addFileErrorMsg("Segment or Page id is lost in row " + (k + 1) + "\r\n");
                hasIdErro = true;
            }
        }
    }

    if (hasIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may change some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadPRRReportData(Sheet sheet, Task task, GlobalSightLocale tLocale) {
    int segmentStartRow = ImplementedCommentsCheckReportGenerator.SEGMENT_START_ROW + 4;
    Set<String> jobIds = new HashSet<String>();

    segId2RequiredTranslation = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2Comment = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();

    String segmentId = null;/*ww w.  j  a  v a 2 s  .  c o m*/
    long segIdLong;
    String updatedText = null;
    String jobIdText = null;
    String comment = null;
    String commentStatus = null;
    boolean hasSegmentIdErro = false;

    int n = 5;
    int m = LOAD_DATA - n;

    qualityAssessment = ExcelUtil.getCellValue(sheet, 6, 1);
    marketSuitabilty = ExcelUtil.getCellValue(sheet, 7, 1);
    taskComment = ExcelUtil.getCellValue(sheet, 8, 1);

    for (int j = segmentStartRow, row = sheet.getLastRowNum(); j <= row; j++) {
        if (cancel)
            return null;

        int x = j * m / row;
        updateProcess(n + x);

        segmentId = ExcelUtil.getCellValue(sheet, j, 11);
        if (StringUtil.isEmpty(segmentId)) {
            break;
        }
        segIdLong = new Long(Long.parseLong(segmentId));

        updatedText = ExcelUtil.getCellValue(sheet, j, 2);
        comment = ExcelUtil.getCellValue(sheet, j, 3);
        commentStatus = ExcelUtil.getCellValue(sheet, j, 5);

        if (EditUtil.isRTLLocale(tLocale))
            updatedText = EditUtil.removeU200F(updatedText);

        jobIdText = ExcelUtil.getCellValue(sheet, j, 10);
        jobIds.add(jobIdText);
        if (segmentId != null && !segmentId.equals("")) {
            if (updatedText != null && !updatedText.equals("")) {
                segId2RequiredTranslation.put(segIdLong, updatedText);
            }
        } else {
            m_errWriter.addFileErrorMsg("Segment id is lost in row " + (j + 1) + "\r\n");
            hasSegmentIdErro = true;
        }
    }
    if (task.isType(Task.TYPE_REVIEW)) {
        segId2RequiredTranslation.clear();
    }

    if (hasSegmentIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may hava changed some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

From source file:com.globalsight.everest.edit.offline.upload.UploadApi.java

License:Apache License

private String loadTVRReportData(Sheet sheet, Task task, GlobalSightLocale tLocale) {
    int segmentStartRow = ImplementedCommentsCheckReportGenerator.SEGMENT_START_ROW;
    Set<String> jobIds = new HashSet<String>();

    segId2RequiredTranslation = new HashMap<Long, String>();
    segId2PageId = new HashMap<Long, Long>();
    segId2FailureType = new HashMap<Long, String>();
    segId2Comment = new HashMap<Long, String>();
    segId2CommentStatus = new HashMap<Long, String>();

    String segmentId = null;/*  ww  w.  j  a  va 2 s.  com*/
    long segIdLong;
    String updatedText = null;
    String jobIdText = null;
    String comment = null;
    String requiredComment = null;
    String commentStatus = null;
    boolean hasSegmentIdErro = false;

    int n = 5;
    int m = LOAD_DATA - n;

    for (int j = segmentStartRow, row = sheet.getLastRowNum(); j <= row; j++) {
        if (cancel)
            return null;

        int x = j * m / row;
        updateProcess(n + x);

        segmentId = ExcelUtil.getCellValue(sheet, j, 12);
        if (StringUtil.isEmpty(segmentId)) {
            break;
        }
        segIdLong = new Long(Long.parseLong(segmentId));

        updatedText = ExcelUtil.getCellValue(sheet, j, 3);
        comment = ExcelUtil.getCellValue(sheet, j, 4);
        requiredComment = ExcelUtil.getCellValue(sheet, j, 5);
        commentStatus = ExcelUtil.getCellValue(sheet, j, 7);

        if (EditUtil.isRTLLocale(tLocale))
            updatedText = EditUtil.removeU200F(updatedText);

        jobIdText = ExcelUtil.getCellValue(sheet, j, 11);
        jobIds.add(jobIdText);
        if (segmentId != null && !segmentId.equals("")) {
            if (updatedText != null && !updatedText.equals("")) {
                segId2RequiredTranslation.put(segIdLong, updatedText);
            }
            if (comment != null && !comment.equals("")) {
                if (requiredComment != null && !requiredComment.equals("")
                        && !StringUtil.equalsIgnoreSpace(requiredComment, "")) {
                    segId2Comment.put(segIdLong, requiredComment);
                }
                segId2CommentStatus.put(segIdLong, commentStatus);
            } else {
                if (requiredComment != null && !requiredComment.equals("")
                        && !StringUtil.equalsIgnoreSpace(requiredComment, "")) {
                    segId2Comment.put(segIdLong, requiredComment);
                    segId2CommentStatus.put(segIdLong, "query");
                }
            }
        } else {
            m_errWriter.addFileErrorMsg("Segment id is lost in row " + (j + 1) + "\r\n");
            hasSegmentIdErro = true;
        }
    }

    if (hasSegmentIdErro) {
        return m_errWriter.buildReportErroPage().toString();
    }

    if (jobIds.size() > 1) {
        m_errWriter.addFileErrorMsg("The job id is not consistent, you may hava changed some of them."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if ((jobIds.size() == 1) && !jobIds.contains(String.valueOf(task.getJobId()))) {
        m_errWriter.addFileErrorMsg("The file you are uploading does not belong to this job."
                + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    } else if (jobIds.size() == 0) {
        m_errWriter.addFileErrorMsg(
                "No job id detected." + "\r\nPlease make sure they are correct and upload again.");
        return m_errWriter.buildReportErroPage().toString();
    }

    return null;
}

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

License:Apache License

/**
 * Create Report File.//from  w w  w  .  j a  v  a2s.co  m
 */
protected File getFile(String p_reportType, Job p_job, Workbook p_workBook) {
    String langInfo = null;
    // If the Workbook has only one sheet, the report name should contain language pair info, such as en_US_de_DE.
    if (p_workBook != null && p_workBook.getNumberOfSheets() == 1) {
        Sheet sheet = p_workBook.getSheetAt(0);
        String srcLang = null, trgLang = null;
        if (p_job != null) {
            srcLang = p_job.getSourceLocale().toString();
        }
        if (srcLang == null) {
            Row languageInfoRow = sheet.getRow(LANGUAGE_INFO_ROW);
            if (languageInfoRow != null) {
                srcLang = languageInfoRow.getCell(0).getStringCellValue();
                srcLang = srcLang.substring(srcLang.indexOf("[") + 1, srcLang.indexOf("]"));
                trgLang = languageInfoRow.getCell(1).getStringCellValue();
                trgLang = trgLang.substring(trgLang.indexOf("[") + 1, trgLang.indexOf("]"));
            } else {
                Row dataRow = sheet.getRow(sheet.getLastRowNum());
                if (dataRow != null) {
                    try {
                        long jobId = (long) dataRow.getCell(0).getNumericCellValue();
                        Job job = ServerProxy.getJobHandler().getJobById(jobId);
                        srcLang = job.getSourceLocale().toString();
                    } catch (Exception e) {
                    }

                }
            }
        }
        if (trgLang == null) {
            trgLang = sheet.getSheetName();
        }
        if (srcLang != null && trgLang != null) {
            langInfo = srcLang + "_" + trgLang;
        }
    }

    return ReportHelper.getReportFile(p_reportType, p_job, ReportConstants.EXTENSION_XLSX, langInfo);
}

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

License:Apache License

/**
 * Create Report File./*from  w ww.ja va 2s  .c om*/
 */
protected File getFile(String p_reportType, Job p_job, Workbook p_workBook) {
    String langInfo = null;
    // If the Workbook has only one sheet, the report name should contain language pair info, such as en_US_de_DE.
    if (p_workBook != null && p_workBook.getNumberOfSheets() == 1) {
        Sheet sheet = p_workBook.getSheetAt(0);
        String srcLang = null, trgLang = null;
        if (p_job != null) {
            srcLang = p_job.getSourceLocale().toString();
        }
        if (srcLang == null) {
            Row languageInfoRow = sheet.getRow(1);
            if (languageInfoRow != null) {
                srcLang = languageInfoRow.getCell(0).getStringCellValue();
                srcLang = srcLang.substring(srcLang.indexOf("[") + 1, srcLang.indexOf("]"));
                trgLang = languageInfoRow.getCell(1).getStringCellValue();
                trgLang = trgLang.substring(trgLang.indexOf("[") + 1, trgLang.indexOf("]"));
            } else {
                Row dataRow = sheet.getRow(sheet.getLastRowNum());
                if (dataRow != null) {
                    try {
                        long jobId = (long) dataRow.getCell(0).getNumericCellValue();
                        Job job = ServerProxy.getJobHandler().getJobById(jobId);
                        srcLang = job.getSourceLocale().toString();
                    } catch (Exception e) {
                    }

                }
            }
        }
        if (trgLang == null) {
            trgLang = sheet.getSheetName();
        }
        if (srcLang != null && trgLang != null) {
            langInfo = srcLang + "_" + trgLang;
        }
    }

    return ReportHelper.getReportFile(p_reportType, p_job, ReportConstants.EXTENSION_XLSX, langInfo);
}

From source file:com.google.gdt.handler.impl.ExcelHandler.java

License:Open Source License

/**
 * /*from ww w  . ja v  a  2  s  . c o  m*/
 * @param inputFile
 * @throws IOException
 * @throws InvalidFormatException
 */
@Override
public void handle(String inputFile, ProgressLevel pLevel) throws IOException, InvalidFormatException {
    String outPutFile = getOuputFileName(inputFile);
    OutputStream outputStream = new FileOutputStream(outPutFile);
    InputStream is = new FileInputStream(inputFile);

    Workbook wb = WorkbookFactory.create(is);
    List<Sheet> sheets = getSheets(wb);

    pLevel.setTrFileName(outPutFile);

    //iterate over sheet
    for (int index = 0; index < sheets.size(); index++) {
        Sheet sheet = sheets.get(index);

        if (sheets.size() > 1) {
            pLevel.setString("Translating sheet " + (index + 1) + "/" + sheets.size());
        }

        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        int rowCount = lastRowNum - firstRowNum;
        // check for empty sheet, don't perform any operation
        if (rowCount == 0) {
            continue;
        }
        pLevel.setValue(0);
        pLevel.setMaxValue(rowCount);
        pLevel.setStringPainted(true);

        int pBarUpdate = 0;
        //iterate over row
        for (Row row : sheet) {
            //iterate over cells
            for (Cell cell : row) {
                if (isInterrupted) {
                    outputStream.close();
                    new File(outPutFile).delete();
                    pLevel.setString("cancelled");
                    return;
                }

                if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    String inputText = cell.getStringCellValue();
                    String translatedTxt = inputText;
                    try {
                        translatedTxt = translator.translate(inputText);
                        cell.setCellValue(translatedTxt);
                    } catch (Exception e) {
                        logger.log(Level.SEVERE,
                                "Input File : " + inputFile + " cannot translate the text : " + inputText, e);
                        continue;
                    }
                }
            } //cell iteration ends
            pBarUpdate++;
            pLevel.setValue(pBarUpdate);
        } //row iteration ends
        pLevel.setValue(rowCount);
    }
    pLevel.setString("done");

    wb.write(outputStream);
    outputStream.close();
}