Example usage for org.apache.poi.hssf.usermodel HSSFSheet shiftRows

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet shiftRows

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet shiftRows.

Prototype

@Override
public void shiftRows(int startRow, int endRow, int n) 

Source Link

Document

Shifts rows between startRow and endRow n number of rows.

Usage

From source file:com.accounting.reportMBean.StockLedgerMBeans.java

public void postProcessXLS(Object document) {
    String startDateString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate4");
    String endDateReading = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
            .get("nepaliDate1");
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFCellStyle headerCellStyle = wb.createCellStyle();
    HSSFCellStyle headerCellStyle1 = wb.createCellStyle();
    HSSFCellStyle headerCellStyle2 = wb.createCellStyle();

    Font headerFont = wb.createFont();
    headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    headerFont.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle.setFont(headerFont);
    headerCellStyle.setAlignment(CellStyle.ALIGN_CENTER);

    Font headerFont1 = wb.createFont();
    headerFont1.setBoldweight(Font.U_SINGLE_ACCOUNTING);
    headerFont1.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle1.setFont(headerFont);
    headerCellStyle1.setAlignment(CellStyle.ALIGN_RIGHT);
    HSSFSheet sheet = wb.getSheetAt(0);
    int noOfColumns = sheet.getRow(0).getLastCellNum();

    Font headerFont3 = wb.createFont();
    headerFont3.setBoldweight(Font.U_SINGLE);
    headerFont3.setFontName(HSSFFont.FONT_ARIAL);
    headerCellStyle2.setFont(headerFont1);
    headerCellStyle2.setAlignment(CellStyle.ALIGN_RIGHT);
    for (int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);/*  w w w  .  j av  a2 s .  com*/
    }
    sheet.shiftRows(0, sheet.getLastRowNum(), 4);

    HSSFRow firstRow = sheet.createRow(0);
    firstRow.createCell(0).setCellValue(reportHeader);
    firstRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow secondRow = sheet.createRow(1);
    secondRow.createCell(0).setCellValue(getLoggedInOffice().getName());
    secondRow.getCell(0).setCellStyle(headerCellStyle);

    HSSFRow thirdRow = sheet.createRow(3);
    String generatedDate = ndc.convertToNepaliDate(new Date());
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss a");

    String time = sdf.format(new Date());
    thirdRow.createCell(0)
            .setCellValue("Generated on:" + generatedDate + " " + time + " by:" + getLoggedInUser().getName());
    thirdRow.getCell(0).setCellStyle(headerCellStyle2);

    HSSFRow fourthRow = sheet.createRow(2);
    fourthRow.createCell(0).setCellValue("From: " + startDateString + " To: " + endDateReading);
    fourthRow.getCell(0).setCellStyle(headerCellStyle);
    System.out.println("The cell count " + cellCount);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, cellCount));
    sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, cellCount));
    for (Row row : sheet) {
        if (row.getRowNum() > 4) {
            for (int i = 3; i < count; i++) {
                String cost = row.getCell(i).getStringCellValue();
                if (cost != null && !cost.isEmpty()) {
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_BLANK);
                    row.getCell(i).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                    row.getCell(i).setCellValue(Double.parseDouble(cost.replace(",", "")));
                }
            }
        }
    }
}

From source file:com.comcast.cats.config.ui.monitoring.reboot.UpTimeAndRebootStatusBean.java

License:Open Source License

public void postProcessXls(Object document) {
    logger.trace("postProcessXls start document " + document);
    if (document != null) {
        HSSFWorkbook workBook = (HSSFWorkbook) document;
        HSSFSheet sheet = workBook.getSheetAt(0);

        HSSFRow headerRow = sheet.getRow(0);

        for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) {
            sheet.setColumnWidth(i, 30 * 265); // width for 40 characters
        }/* w ww.  ja v a  2 s.c  o  m*/

        sheet.shiftRows(0, sheet.getLastRowNum(), 5); // shift rows 0 to n
                                                      // by 1 to get space
                                                      // for header
        sheet.addMergedRegion(CellRangeAddress.valueOf("A1:F3"));

        HSSFFont headerFont = workBook.createFont();
        headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFCellStyle headerCellStyle = workBook.createCellStyle();
        headerCellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
        headerCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        headerCellStyle.setFont(headerFont);
        headerCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        headerCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCell headerCell = headerRow.createCell(0);
        headerCell.setCellStyle(headerCellStyle);
        headerCell.setCellValue("CATS Uptime and Reboot Status : " + (new Date()));

        HSSFCellStyle metaDataCellStyle = workBook.createCellStyle();
        metaDataCellStyle.setFont(headerFont);

        HSSFRow metaDataRow = sheet.getRow(3);
        if (metaDataRow == null) {
            metaDataRow = sheet.createRow(3);
        }
        HSSFCell metaDataKey = metaDataRow.createCell(0);
        metaDataKey.setCellStyle(metaDataCellStyle);
        metaDataKey.setCellValue("CATS Instance");

        HSSFCell metaDataValue = metaDataRow.createCell(1);
        metaDataValue.setCellStyle(metaDataCellStyle);
        metaDataValue.setCellValue(AuthController.getHostAddress());

        HSSFCellStyle datatTableHeaderCellStyle = workBook.createCellStyle();
        datatTableHeaderCellStyle.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
        datatTableHeaderCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        datatTableHeaderCellStyle.setFont(headerFont);

        HSSFRow actualDataTableHeaderRow = sheet.getRow(5);
        for (int i = 0; i < actualDataTableHeaderRow.getPhysicalNumberOfCells(); i++) {
            HSSFCell cell = actualDataTableHeaderRow.getCell(i);
            if (cell != null) {
                String cellValue = cell.getStringCellValue();
                cellValue = cellValue.replace("<br/> ", ""); // replace
                                                             // any line
                                                             // breaks
                cell.setCellValue(cellValue);
                cell.setCellStyle(datatTableHeaderCellStyle);
            }
        }

    }
    logger.trace("postProcessXls end");
}

From source file:com.photon.phresco.framework.commons.FrameworkUtil.java

License:Apache License

public boolean deleteTestSuitesFromXls(String filePath, String testSuiteName) {
    boolean hasTrue = false;
    Iterator<Row> rowIterator;
    try {// ww  w  .j av a  2 s . c  om
        FileInputStream myInput = new FileInputStream(filePath);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput);

        HSSFSheet mySheet = myWorkBook.getSheetAt(0);
        rowIterator = mySheet.rowIterator();
        for (int i = 0; i <= 2; i++) {
            rowIterator.next();
        }
        while (rowIterator.hasNext()) {
            Row next = rowIterator.next();
            if (getValue(next.getCell(2)).equalsIgnoreCase(testSuiteName)) {
                mySheet.removeRow(next);
                int rowNum = next.getRowNum();
                int newNum = rowNum + 1;
                mySheet.shiftRows(newNum, mySheet.getLastRowNum(), -1);
                int numberOfSheets = myWorkBook.getNumberOfSheets();
                for (int j = 0; j < numberOfSheets; j++) {
                    HSSFSheet mySheet1 = myWorkBook.getSheetAt(j);
                    if (mySheet1.getSheetName().equalsIgnoreCase(testSuiteName)) {
                        myWorkBook.removeSheetAt(j);
                        hasTrue = true;
                        break;
                    }
                }
                myInput.close();
                FileOutputStream outFile = new FileOutputStream(filePath);
                myWorkBook.write(outFile);
                outFile.close();
                break;
            }
        }
    } catch (Exception e) {

    }

    return hasTrue;
}

From source file:com.photon.phresco.framework.commons.FrameworkUtil.java

License:Apache License

public boolean deleteTestCasesFromXls(String filePath, String testSuiteName, String testCaseId) {
    boolean hasTrue = false;
    List<TestCase> testCases = new ArrayList<TestCase>();
    TestCase tstCase = new TestCase();
    Iterator<Row> rowIterator;
    try {//from  w  ww . j a  v  a2  s.  co m
        FileInputStream myInput = new FileInputStream(filePath);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput);
        int numberOfSheets = myWorkBook.getNumberOfSheets();
        for (int j = 0; j < numberOfSheets; j++) {
            HSSFSheet mySheet = myWorkBook.getSheetAt(j);
            if (mySheet.getSheetName().equals(testSuiteName)) {
                rowIterator = mySheet.rowIterator();
                for (int i = 0; i <= 23; i++) {
                    rowIterator.next();
                }
                while (rowIterator.hasNext()) {
                    Row next = rowIterator.next();
                    if (testCaseId.equalsIgnoreCase(getValue(next.getCell(3)))) {
                        tstCase = readTest(next);
                        mySheet.removeRow(next);
                        int rowNum = next.getRowNum();
                        int newNum = rowNum + 1;
                        HSSFRow row = mySheet.getRow(newNum);
                        if (row != null) {
                            mySheet.shiftRows(newNum, mySheet.getLastRowNum(), -1);
                        }
                        hasTrue = true;
                        break;
                    }
                }
            }
        }

        if (hasTrue) {
            for (int j = 0; j < numberOfSheets; j++) {
                HSSFSheet myHSSFSheet = myWorkBook.getSheetAt(j);
                if (myHSSFSheet.getSheetName().equals(testSuiteName)) {
                    rowIterator = myHSSFSheet.rowIterator();
                    for (int i = 0; i <= 23; i++) {
                        rowIterator.next();
                    }
                    while (rowIterator.hasNext()) {
                        Row next = rowIterator.next();
                        TestCase createObject = readTest(next);
                        if (StringUtils.isNotEmpty(createObject.getTestCaseId())) {
                            testCases.add(createObject);
                        }
                    }
                    float totalPass = 0;
                    float totalFail = 0;
                    float totalNotApplicable = 0;
                    float totalBlocked = 0;
                    int totalTestCases = testCases.size();
                    for (TestCase testCase : testCases) {
                        String testCaseStatus = testCase.getStatus();
                        if (testCaseStatus.equalsIgnoreCase("success")) {
                            totalPass = totalPass + 1;
                        } else if (testCaseStatus.equalsIgnoreCase("failure")) {
                            totalFail = totalFail + 1;
                        } else if (testCaseStatus.equalsIgnoreCase("notApplicable")) {
                            totalNotApplicable = totalNotApplicable + 1;
                        } else if (testCaseStatus.equalsIgnoreCase("blocked")) {
                            totalBlocked = totalBlocked + 1;
                        }
                    }

                    //                      if(tstCase.getStatus().equalsIgnoreCase("success")) {
                    //                         totalPass = totalPass - 1;
                    //                      } else if (tstCase.getStatus().equalsIgnoreCase("failure")) {
                    //                         totalFail = totalFail - 1;
                    //                      } else if (tstCase.getStatus().equalsIgnoreCase("notApplicable")) {
                    //                         totalNotApplicable = totalNotApplicable - 1;
                    //                      } else if (tstCase.getStatus().equalsIgnoreCase("blocked")) {
                    //                         totalBlocked = totalBlocked - 1;
                    //                      } 

                    HSSFSheet mySheet1 = myWorkBook.getSheetAt(0);
                    rowIterator = mySheet1.rowIterator();
                    for (int i = 0; i <= 2; i++) {
                        rowIterator.next();
                    }
                    while (rowIterator.hasNext()) {
                        Row next1 = rowIterator.next();
                        if (StringUtils.isNotEmpty(getValue(next1.getCell(2)))
                                && !getValue(next1.getCell(2)).equalsIgnoreCase("Total")) {
                            TestSuite createObject = createObject(next1);
                            if (StringUtils.isNotEmpty(tstCase.getTestCaseId())
                                    && createObject.getName().equals(testSuiteName)) {
                                updateIndex(totalPass, totalFail, totalNotApplicable, totalBlocked, next1,
                                        totalTestCases, "delete");
                            }
                        }
                    }
                }
            }

            myInput.close();
            FileOutputStream outFile = new FileOutputStream(filePath);
            myWorkBook.write(outFile);
            outFile.close();
        }
    } catch (Exception e) {

    }

    return hasTrue;
}

From source file:com.vportal.portlet.vcms.action.ReportAction.java

License:Open Source License

public void setReportByType(int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId, String language,
        long statusId, Date fromDate, Date toDate, String byUser) throws Exception {

    HSSFRow row;/*from  w  ww.  j  av a 2s . com*/

    List listType = VcmsTypeServiceUtil.getTypesByS_L(groupId, language);
    sheet.shiftRows(y, sheet.getLastRowNum(), 1);

    //date
    row = sheet.createRow(y - 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), " T\u1eeb ng\u00e0y " + ActionUtil.dateParser(fromDate)
            + " \u0111\u1ebfn ng\u00e0y " + ActionUtil.dateParser(toDate), wb);

    row = sheet.createRow(y);

    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "Lo\u1ea1i tin", wb);
    ReportUtil.createCellBold(row, (short) (x + 2), "T\u00e1c ph\u1ea9m", wb);

    int totalArticle = 0;
    int stt = 0;
    for (int j = 0; j < listType.size(); j++) {
        VcmsType vcmsType = (VcmsType) listType.get(j);
        sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
        row = sheet.createRow(1 + y++);

        int total = VcmsArticleServiceUtil.countByType(groupId, language, statusId,
                Long.valueOf(vcmsType.getTypeId()), fromDate, toDate, byUser);
        totalArticle += total;

        if (vcmsType.getTypeId() != null) {
            ReportUtil.createCell(row, (short) (x), ++stt, wb);
            ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + vcmsType.getName() + "", wb);
            ReportUtil.createCell(row, (short) (x + 2), total, wb);
        }

    }
    //total count
    row = sheet.createRow(y + 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), "T\u1ed5ng s\u1ed1 b\u00e0i vi\u1ebft", wb);
    ReportUtil.createCellNoBorder(row, (short) (x + 2), String.valueOf(totalArticle), wb);

    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(
                PortalUtil.getPortalWebDir() + "/VCMS-portlet/html/portlet/vcms/report/file/reportByType.xls");
        wb.write(fileOut);

    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }
}

From source file:com.vportal.portlet.vcms.action.ReportAction.java

License:Open Source License

public void setCategoryReport(List portionResults, int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId,
        String language, String parentId, Date dateFrom, Date dateTo, String byUser) throws Exception {
    int totalStatus = VcmsStatusLocalServiceUtil.countByGroupId(groupId);
    List statusResults = VcmsStatusLocalServiceUtil.getByGroupId(groupId, 0, totalStatus);

    HSSFRow row;/* w  w  w  .  j av  a2  s . co  m*/
    HSSFCell cell;
    User userBean;

    sheet.shiftRows(y, sheet.getLastRowNum(), 1);

    row = sheet.createRow(y - 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), " T\u1eeb ng\u00e0y " + ActionUtil.dateParser(dateFrom)
            + " \u0111\u1ebfn ng\u00e0y " + ActionUtil.dateParser(dateTo), wb);

    row = sheet.createRow(y);
    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "Chuy\u00ean m\u1ee5c", wb);

    for (int j = 0; j < totalStatus; j++) {
        VcmsStatus vcmsStatus = (VcmsStatus) statusResults.get(j);
        ReportUtil.createCellBold(row, (short) (x + 2 + j), "" + vcmsStatus.getName() + "", wb);
    }

    int stt = 0;
    int totalArticle = 0;
    for (int i = portionResults.size() - 1; i >= 0; --i) {
        VcmsPortion vcmsPortion = (VcmsPortion) portionResults.get(i);
        List categoryByPortion = ActionUtil.getListCategoryReport(groupId, vcmsPortion.getPortionId(), parentId,
                language);

        for (int j = 0; j < categoryByPortion.size(); j++) {
            VcmsCategory vcmsCategory = (VcmsCategory) categoryByPortion.get(j);
            sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
            row = sheet.createRow(1 + y++);

            if (vcmsCategory.getName() != null) {
                ReportUtil.createCell(row, (short) (x), ++stt, wb);
            }
            if (vcmsCategory.getName() != null) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + vcmsCategory.getName() + "", wb);
            }
            for (int k = 0; k < totalStatus; k++) {
                int countArticles = 0;
                VcmsStatus status = (VcmsStatus) statusResults.get(k);

                countArticles = VcmsArticleServiceUtil.countByC_P_L_S_D(vcmsCategory.getCategoryId(), groupId,
                        language, status.getStatusId(), dateFrom, dateTo, byUser);
                totalArticle += countArticles;

                ReportUtil.createCell(row, (short) (x + 2 + k), countArticles, wb);
            }
        }

    }

    row = sheet.createRow(y + 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), "T\u1ed5ng s\u1ed1 b\u00e0i vi\u1ebft", wb);
    ReportUtil.createCellNoBorder(row, (short) (x + 2), String.valueOf(totalArticle), wb);

    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(PortalUtil.getPortalWebDir()
                + "/VCMS-portlet/html/portlet/vcms/report/file/reportCategory.xls");
        wb.write(fileOut);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }
}

From source file:com.vportal.portlet.vcms.action.ReportAction.java

License:Open Source License

public void setReportByDate(int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId, String language,
        long statusId, Date dateFrom, Date dateTo, String byUser, String[] strType, int begin, int end)
        throws Exception {

    List listNews = new ArrayList();

    listNews = VcmsArticleServiceUtil.listArticleByDateTypes(groupId, language, statusId, dateFrom, dateTo,
            byUser, strType, begin, end);

    HSSFRow row;/*from   w  ww.ja v a2  s.  c o  m*/
    HSSFCell cell;
    User userBean;

    VcmsStatus vcmsStatus = VcmsStatusLocalServiceUtil.getVcmsStatus(statusId);

    sheet.shiftRows(y, sheet.getLastRowNum(), 1);
    row = sheet.createRow(y - 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), " T\u1eeb ng\u00e0y " + ActionUtil.dateParser(dateFrom)
            + " \u0111\u1ebfn ng\u00e0y " + ActionUtil.dateParser(dateTo), wb);

    row = sheet.createRow(y);

    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "Ti\u00eau \u0111\u1ec1", wb);
    ReportUtil.createCellBold(row, (short) (x + 2), "Ng\u00e0y \u0111\u0103ng", wb);
    ReportUtil.createCellBold(row, (short) (x + 3), "Ng\u01b0\u1eddi t\u1ea1o", wb);
    ReportUtil.createCellBold(row, (short) (x + 4), "Ng\u01b0\u1eddi duy\u1ec7t", wb);
    ReportUtil.createCellBold(row, (short) (x + 5), "Ng\u01b0\u1eddi xu\u1ea5t b\u1ea3n", wb);
    ReportUtil.createCellBold(row, (short) (x + 6), "Lo\u1ea1i tin", wb);

    int stt = 0;
    for (int j = 0; j < listNews.size(); j++) {
        VcmsArticle vcmsAr = (VcmsArticle) listNews.get(j);

        String typeNames = "";
        try {
            typeNames += ReportUtil.getTypeNames(vcmsAr.getArticleId());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
        row = sheet.createRow(1 + y++);

        if (vcmsAr != null) {
            ReportUtil.createCell(row, (short) (x), ++stt, wb);
            ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + vcmsAr.getTitle() + "", wb);
            ReportUtil.createCell(row, (short) (x + 2), ActionUtil.dateParser(vcmsAr.getPublishedDate()), wb);

            try {
                User userCreate = UserServiceUtil.getUserById(Long.parseLong(vcmsAr.getCreatedByUser()));
                ReportUtil.createCellAlignLeft(row, (short) (x + 3), userCreate.getFullName(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 3), "User \u0111\u00e3 b\u1ecb x\u00f3a", wb);
            }

            try {
                User modifieddUser = UserServiceUtil.getUserById(Long.parseLong(vcmsAr.getModifiedByUser()));
                ReportUtil.createCellAlignLeft(row, (short) (x + 4), modifieddUser.getFullName(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 4), "User \u0111\u00e3 b\u1ecb x\u00f3a", wb);
            }

            try {
                User publishedUser = UserServiceUtil.getUserById(Long.parseLong(vcmsAr.getPublishedByUser()));
                ReportUtil.createCellAlignLeft(row, (short) (x + 5), publishedUser.getFullName(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 5), "User \u0111\u00e3 b\u1ecb x\u00f3a", wb);
            }

            ReportUtil.createCellAlignLeft(row, (short) (x + 6), typeNames, wb);
        }

    }

    row = sheet.createRow(y + 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), "T\u1ed5ng s\u1ed1 b\u00e0i vi\u1ebft", wb);
    ReportUtil.createCellNoBorder(row, (short) (x + 2), String.valueOf(listNews.size()), wb);

    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(
                PortalUtil.getPortalWebDir() + "/VCMS-portlet/html/portlet/vcms/report/file/reportByDate.xls");
        wb.write(fileOut);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }
}

From source file:com.vportal.portlet.vcms.action.ReportAction.java

License:Open Source License

public void setUserReport(List userList, int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId,
        String language, String parentId, long statusId, Date dateFrom, Date dateTo) throws Exception {

    List listType = VcmsTypeServiceUtil.getTypesByS_L(groupId, language);

    HSSFRow row;/*from  w ww  . j a  v  a2s.  c o m*/
    User userBean;

    sheet.shiftRows(y, sheet.getLastRowNum(), 1);

    row = sheet.createRow(y - 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), " T\u1eeb ng\u00e0y " + ActionUtil.dateParser(dateFrom)
            + " \u0111\u1ebfn ng\u00e0y " + ActionUtil.dateParser(dateTo), wb);

    row = sheet.createRow(y);
    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "H\u1ecd T\u00ean", wb);

    for (int j = 0; j < listType.size(); j++) {
        VcmsType vcmsType = (VcmsType) listType.get(j);
        ReportUtil.createCellBold(row, (short) (x + 2 + j), "" + vcmsType.getName() + "", wb);
    }
    ReportUtil.createCellBold(row, (short) (x + 2 + listType.size()), "C\u00e1c lo\u1ea1i tin kh\u00e1c", wb);

    int stt = 0;
    int totalArticle = 0;

    for (int i = userList.size() - 1; i >= 0; --i) {
        userBean = (User) userList.get(i);
        sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
        row = sheet.createRow(1 + y++);

        if (userBean != null) {
            ReportUtil.createCell(row, (short) (x), ++stt, wb);
        }
        if (userBean != null) {
            ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + userBean.getFullName() + "", wb);
        }

        for (int j = 0; j < listType.size(); j++) {
            VcmsType vcmsType = (VcmsType) listType.get(j);
            int countArticle = 0;
            if (!parentId.equals("0")) {
                countArticle = VcmsArticleServiceUtil.countByUser(groupId, language, parentId, statusId,
                        Long.valueOf(vcmsType.getTypeId()), dateFrom, dateTo,
                        String.valueOf(userBean.getUserId()));
            } else {

                countArticle = VcmsArticleServiceUtil.countByType(groupId, language, statusId,
                        Long.valueOf(vcmsType.getTypeId()), dateFrom, dateTo,
                        String.valueOf(userBean.getUserId()));
            }

            ReportUtil.createCell(row, (short) (x + 2 + j), countArticle, wb);
            totalArticle += countArticle;
        }

        //other type
        int countArticleAllCatNotInType = 0;
        if (!parentId.equals("0")) {
            countArticleAllCatNotInType = VcmsArticleServiceUtil.countArticleNotInType(groupId, language,
                    parentId, statusId, dateFrom, dateTo, String.valueOf(userBean.getUserId()));
        } else {
            countArticleAllCatNotInType = VcmsArticleServiceUtil.countArticleAllCatNotInType(groupId, language,
                    statusId, dateFrom, dateTo, String.valueOf(userBean.getUserId()));
        }

        ReportUtil.createCell(row, (short) (x + 2 + listType.size()), countArticleAllCatNotInType, wb);
        totalArticle += countArticleAllCatNotInType;
    }

    row = sheet.createRow(y + 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), "T\u1ed5ng s\u1ed1 b\u00e0i vi\u1ebft", wb);
    ReportUtil.createCellNoBorder(row, (short) (x + 2), String.valueOf(totalArticle), wb);

    FileOutputStream fileOut = null;
    try {
        fileOut = new FileOutputStream(
                PortalUtil.getPortalWebDir() + "/VCMS-portlet/html/portlet/vcms/report/file/reportUser.xls");
        wb.write(fileOut);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }

}

From source file:com.vportal.portlet.vdoc.action.VDocManage.java

License:Open Source License

public void setReportByDate(int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId, String language,
        int statusId, Date dateFrom, Date dateTo) throws Exception {
    List listnew = new ArrayList();
    listnew = vdocDocumentServiceUtil.getDocbyModifyDate(groupId, language, dateFrom, dateTo, statusId);
    HSSFRow row;//from   www  .ja  v  a2s.c o m
    HSSFCell cell;
    sheet.shiftRows(sheet.getLastRowNum(), y, 1);
    row = sheet.createRow(y - 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), " T\u1eeb ng\u00e0y " + ActionUtil.dateParser(dateFrom)
            + " \u0111\u1ebfn ng\u00e0y " + ActionUtil.dateParser(dateTo), wb);

    row = sheet.createRow(y);

    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "Ti\u00eau \u0111\u1ec1", wb);
    ReportUtil.createCellBold(row, (short) (x + 2), "Nga\u0300y xu\u00E2\u0301t ba\u0309n", wb);
    ReportUtil.createCellBold(row, (short) (x + 3), "Nga\u0300y chi\u0309nh s\u01B0\u0309a", wb);
    ReportUtil.createCellBold(row, (short) (x + 4), "Ng\u01B0\u01A1\u0300i duy\u00EA\u0323t", wb);
    ReportUtil.createCellBold(row, (short) (x + 5), "Ng\u01B0\u01A1\u0300i chi\u0309nh s\u01B0\u0309a", wb);
    ReportUtil.createCellBold(row, (short) (x + 6), "\u0110\u01A1n vi\u0323", wb);
    int stt = 0;
    for (int j = 0; j < listnew.size(); j++) {
        // VcmsArticle vcmsAr = (VcmsArticle) listNews.get(j);
        vdocDocument vdoc = (vdocDocument) listnew.get(j);

        sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
        row = sheet.createRow(1 + y++);

        if (vdoc != null) {
            ReportUtil.createCell(row, (short) (x), ++stt, wb);
            ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + vdoc.getTitle() + "", wb);
            ReportUtil.createCell(row, (short) (x + 2), ActionUtil.dateParser(vdoc.getPublishedDate()), wb);

            try {
                // User userCreate =
                // UserServiceUtil.getUserById(vdoc.getCreatedByUser());
                ReportUtil.createCellAlignLeft(row, (short) (x + 3),
                        ActionUtil.dateParser(vdoc.getModifiedDate()), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 3), "Ng&#224;y ch&#7881;nh s&#7917;a", wb);
            }

            try {
                User modifieddUser = UserServiceUtil.getUserById(vdoc.getPublishedByUser());
                ReportUtil.createCellAlignLeft(row, (short) (x + 4), modifieddUser.getFullName(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 4), "Ng\u01B0\u01A1\u0300i duy\u00EA\u0323t",
                        wb);
            }

            try {
                User publishedUser = UserServiceUtil.getUserById(vdoc.getModifiedByUser());
                ReportUtil.createCellAlignLeft(row, (short) (x + 5), publishedUser.getFullName(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 5),
                        "Ng\u01B0\u01A1\u0300i chi\u0309nh s\u01B0\u0309a", wb);
            }
            try {

                ReportUtil.createCellAlignLeft(row, (short) (x + 6), vdoc.getOrgRels(), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 6), "\u0110\u01A1n vi\u0323", wb);
            }

        }

    }

    row = sheet.createRow(y + 2);
    ReportUtil.createCellNoBorder(row, (short) (x + 1), "T\u1ed5ng s\u1ed1 b\u00e0i vi\u1ebft", wb);
    ReportUtil.createCellNoBorder(row, (short) (x + 2), String.valueOf(listnew.size()), wb);

    FileOutputStream fileOut = null;
    String porttalDir = PortalUtil.getPortalWebDir();
    try {
        fileOut = new FileOutputStream(porttalDir.substring(0, porttalDir.indexOf("ROOT"))
                + "//VDoc-portlet//html//vdoc_manage//statistics//file//reportByDate.xls");
        wb.write(fileOut);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }
}

From source file:com.vportal.portlet.vdoc.action.VDocManage.java

License:Open Source License

public void setReportByOrg(int y, int x, HSSFSheet sheet, HSSFWorkbook wb, long groupId, String language,
        int statusId) throws Exception {
    List listnew = new ArrayList();
    listnew = vdocOrgServiceUtil.getOrgByG_L(groupId, language);
    HSSFRow row;/* w w  w.jav a  2  s  .co m*/
    HSSFCell cell;
    sheet.shiftRows(sheet.getLastRowNum(), y, 1);
    row = sheet.createRow(y - 2);
    row = sheet.createRow(y);

    ReportUtil.createCellBold(row, (short) (x), "S\u1ed1 TT", wb);
    ReportUtil.createCellBold(row, (short) (x + 1), "C\u01A1 quan - \u0110\u01A1n vi\u0323", wb);
    ReportUtil.createCellBold(row, (short) (x + 2), "Ch\u01A1\u0300 xu\u00E2\u0301t ba\u0309n", wb);
    ReportUtil.createCellBold(row, (short) (x + 3), "\u0110a\u0303 xu\u00E2\u0301t ba\u0309n", wb);
    ReportUtil.createCellBold(row, (short) (x + 4), "Chi\u0309nh s\u01B0\u0309a", wb);
    int stt = 0;
    for (int j = 0; j < listnew.size(); j++) {
        // VcmsArticle vcmsAr = (VcmsArticle) listNews.get(j);
        vdocOrg org = (vdocOrg) listnew.get(j);

        sheet.shiftRows(y + 1, sheet.getLastRowNum(), 1);
        row = sheet.createRow(1 + y++);

        if (org != null) {
            ReportUtil.createCell(row, (short) (x), ++stt, wb);
            ReportUtil.createCellAlignLeft(row, (short) (x + 1), "" + org.getName() + "", wb);
            ReportUtil.createCell(row, (short) (x + 2),
                    vdocDORelServiceUtil.countCategory_approving(org.getOrgId()), wb);

            try {
                // User userCreate =
                // UserServiceUtil.getUserById(vdoc.getCreatedByUser());
                ReportUtil.createCellAlignLeft(row, (short) (x + 3),
                        String.valueOf(vdocDORelServiceUtil.countCategory_approving(org.getOrgId())), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 3), "...", wb);
            }

            try {

                ReportUtil.createCellAlignLeft(row, (short) (x + 4),
                        String.valueOf(vdocDORelServiceUtil.countCategory_approving(org.getOrgId())), wb);
            } catch (Exception ex) {
                ReportUtil.createCellAlignLeft(row, (short) (x + 4), "...", wb);
            }

        }

    }

    FileOutputStream fileOut = null;
    String porttalDir = PortalUtil.getPortalWebDir();
    try {
        fileOut = new FileOutputStream(porttalDir.substring(0, porttalDir.indexOf("ROOT"))
                + "//VDoc-portlet//html//vdoc_manage//statistics//file//reportByOrg.xls");
        wb.write(fileOut);
    } catch (Exception ex) {
        System.out.println(ex.toString());
    } finally {
        fileOut.flush();
        fileOut.close();
    }
}