Example usage for org.apache.poi.xssf.usermodel XSSFSheet getSheetName

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getSheetName

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFSheet getSheetName.

Prototype

@Override
public String getSheetName() 

Source Link

Document

Returns the name of this sheet

Usage

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

License:Apache License

public void addNew(String filePath, String testName, String cellValue[]) throws PhrescoException {
    try {/*w  ww  . j  av  a2 s  . co  m*/
        //FileInputStream myInput = new FileInputStream(filePath);

        int numCol;
        int cellno = 0;
        CellStyle tryStyle[] = new CellStyle[20];
        String sheetName = testName;
        //String cellValue[] = {"","",testName,success, fail,"","","",total,testCoverage,"","",""};
        Iterator<Row> rowIterator;
        File testDir = new File(filePath);
        StringBuilder sb = new StringBuilder(filePath);
        if (testDir.isDirectory()) {
            FilenameFilter filter = new PhrescoFileFilter("", "xlsx");
            File[] listFiles = testDir.listFiles(filter);
            if (listFiles.length != 0) {
                for (File file1 : listFiles) {
                    if (file1.isFile()) {
                        sb.append(File.separator);
                        sb.append(file1.getName());
                        break;
                    }
                }
                FileInputStream myInput = new FileInputStream(sb.toString());
                OPCPackage opc = OPCPackage.open(myInput);

                XSSFWorkbook myWorkBook = new XSSFWorkbook(opc);
                XSSFSheet mySheet = myWorkBook.getSheetAt(0);
                rowIterator = mySheet.rowIterator();
                numCol = 13;
                Row next;
                for (Cell cell : mySheet.getRow((mySheet.getLastRowNum()) - 2)) {
                    tryStyle[cellno] = cell.getCellStyle();
                    cellno = cellno + 1;
                }
                do {

                    int flag = 0;
                    next = rowIterator.next();
                    if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")
                            && ((mySheet.getLastRowNum() - next.getRowNum()) < 3)) {
                        for (Cell cell : next) {
                            cell.setCellType(1);
                            if (cell.getStringCellValue().equalsIgnoreCase("total")) {
                                mySheet.shiftRows((mySheet.getLastRowNum() - 1),
                                        (mySheet.getPhysicalNumberOfRows() - 1), 1);
                                flag = 1;
                            }
                            if (flag == 1)
                                break;
                        }
                        if (flag == 1)
                            break;
                    }
                } while (rowIterator.hasNext());

                Row r = null;
                if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")) {
                    r = mySheet.createRow(next.getRowNum() - 1);

                } else {
                    r = mySheet.createRow(next.getRowNum() + 1);
                }
                for (int i = 0; i < numCol; i++) {
                    Cell cell = r.createCell(i);
                    cell.setCellValue(cellValue[i]);
                    // used only when sheet is 'index'
                    if (i == 2)
                        sheetName = cellValue[i];

                    cell.setCellStyle(tryStyle[i]);
                }
                if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")) {
                    Sheet fromSheet = myWorkBook.getSheetAt((myWorkBook.getNumberOfSheets() - 1));
                    Sheet toSheet = myWorkBook.createSheet(sheetName);
                    int i = 0;
                    Iterator<Row> copyFrom = fromSheet.rowIterator();
                    Row fromRow, toRow;
                    CellStyle newSheetStyle[] = new CellStyle[20];
                    Integer newSheetType[] = new Integer[100];
                    String newSheetValue[] = new String[100];
                    do {
                        fromRow = copyFrom.next();
                        if (fromRow.getRowNum() == 24) {
                            break;
                        }
                        toRow = toSheet.createRow(i);
                        int numCell = 0;
                        for (Cell cell : fromRow) {
                            Cell newCell = toRow.createCell(numCell);

                            cell.setCellType(1);

                            newSheetStyle[numCell] = cell.getCellStyle();
                            newCell.setCellStyle(newSheetStyle[numCell]);

                            newSheetType[numCell] = cell.getCellType();
                            newCell.setCellType(newSheetType[numCell]);
                            if (fromRow.getCell(0).getStringCellValue().length() != 1
                                    && fromRow.getCell(0).getStringCellValue().length() != 2
                                    && fromRow.getCell(0).getStringCellValue().length() != 3) {
                                newSheetValue[numCell] = cell.getStringCellValue();
                                newCell.setCellValue(newSheetValue[numCell]);
                            }

                            numCell = numCell + 1;
                        }
                        i = i + 1;
                    } while (copyFrom.hasNext());
                }
                // write to file
                FileOutputStream fileOut = new FileOutputStream(sb.toString());
                myWorkBook.write(fileOut);
                myInput.close();
                fileOut.close();
            } else {
                FilenameFilter xlsFilter = new PhrescoFileFilter("", "xls");
                File[] xlsListFiles = testDir.listFiles(xlsFilter);
                if (xlsListFiles.length != 0) {
                    for (File file2 : xlsListFiles) {
                        if (file2.isFile()) {
                            sb.append(File.separator);
                            sb.append(file2.getName());
                            break;
                        }
                    }
                    FileInputStream myInput = new FileInputStream(sb.toString());
                    HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput);

                    HSSFSheet mySheet = myWorkBook.getSheetAt(0);
                    rowIterator = mySheet.rowIterator();
                    numCol = 13;
                    Row next;
                    for (Cell cell : mySheet.getRow((mySheet.getLastRowNum()) - 2)) {
                        tryStyle[cellno] = cell.getCellStyle();
                        cellno = cellno + 1;
                    }
                    do {

                        int flag = 0;
                        next = rowIterator.next();
                        if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")
                                && ((mySheet.getLastRowNum() - next.getRowNum()) < 3)) {
                            for (Cell cell : next) {
                                cell.setCellType(1);
                                if (cell.getStringCellValue().equalsIgnoreCase("total")) {
                                    mySheet.shiftRows((mySheet.getLastRowNum() - 1),
                                            (mySheet.getPhysicalNumberOfRows() - 1), 1);
                                    flag = 1;
                                }
                                if (flag == 1)
                                    break;
                            }
                            if (flag == 1)
                                break;
                        }
                    } while (rowIterator.hasNext());

                    Row r = null;
                    if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")) {
                        r = mySheet.createRow(mySheet.getLastRowNum() - 2);
                    } else {
                        r = mySheet.createRow(next.getRowNum() + 1);
                    }
                    for (int i = 0; i < numCol; i++) {
                        Cell cell = r.createCell(i);
                        cell.setCellValue(cellValue[i]);
                        // used only when sheet is 'index'
                        if (i == 2)
                            sheetName = cellValue[i];

                        cell.setCellStyle(tryStyle[i]);
                    }
                    if ((mySheet.getSheetName().trim()).equalsIgnoreCase("Index")) {
                        Sheet fromSheet = myWorkBook.getSheetAt((myWorkBook.getNumberOfSheets() - 1));
                        Sheet toSheet = myWorkBook.createSheet(sheetName);
                        int i = 0;
                        Iterator<Row> copyFrom = fromSheet.rowIterator();
                        Row fromRow, toRow;
                        CellStyle newSheetStyle[] = new CellStyle[20];
                        Integer newSheetType[] = new Integer[100];
                        String newSheetValue[] = new String[100];
                        do {
                            fromRow = copyFrom.next();
                            if (fromRow.getRowNum() == 24) {
                                break;
                            }
                            toRow = toSheet.createRow(i);
                            int numCell = 0;
                            for (Cell cell : fromRow) {
                                Cell newCell = toRow.createCell(numCell);

                                cell.setCellType(1);

                                newSheetStyle[numCell] = cell.getCellStyle();
                                newCell.setCellStyle(newSheetStyle[numCell]);

                                newSheetType[numCell] = cell.getCellType();
                                newCell.setCellType(newSheetType[numCell]);
                                if (fromRow.getCell(0).getStringCellValue().length() != 1
                                        && fromRow.getCell(0).getStringCellValue().length() != 2
                                        && fromRow.getCell(0).getStringCellValue().length() != 3) {
                                    newSheetValue[numCell] = cell.getStringCellValue();
                                    newCell.setCellValue(newSheetValue[numCell]);
                                }

                                numCell = numCell + 1;
                                if (numCell == 15) {
                                    break;
                                }
                            }
                            i = i + 1;
                        } while (copyFrom.hasNext());
                    }
                    // write to file
                    FileOutputStream fileOut = new FileOutputStream(sb.toString());
                    myWorkBook.write(fileOut);
                    myInput.close();
                    fileOut.close();
                } else {
                    FilenameFilter odsFilter = new PhrescoFileFilter("", "ods");
                    File[] odsListFiles = testDir.listFiles(odsFilter);
                    for (File file1 : odsListFiles) {
                        if (file1.isFile()) {
                            sb.append(File.separator);
                            sb.append(file1.getName());
                            break;
                        }
                    }
                    File file = new File(sb.toString());
                    addTestSuiteToOds(file, cellValue);
                }
            }
        }
    } catch (Exception e) {
        //         throw new PhrescoException(e);
    }
}

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

License:Apache License

private void writeTestCasesToXLSX(String testSuiteName, String[] cellValue, String status, int numCol,
        int cellno, CellStyle[] tryStyle, StringBuilder sb) throws PhrescoException {
    Iterator<Row> rowIterator;
    try {//from ww w.  java2  s .  c om
        FileInputStream myInput = new FileInputStream(sb.toString());
        OPCPackage opc = OPCPackage.open(myInput);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(opc);
        int numberOfSheets = myWorkBook.getNumberOfSheets();
        for (int j = 0; j < numberOfSheets; j++) {
            XSSFSheet mySheet = myWorkBook.getSheetAt(j);
            if (mySheet.getSheetName().equals(testSuiteName)) {
                rowIterator = mySheet.rowIterator();
                Row next;
                for (Cell cell : mySheet.getRow((mySheet.getLastRowNum()) - 2)) {
                    tryStyle[cellno] = cell.getCellStyle();
                    cellno = cellno + 1;
                }
                float totalPass = 0;
                float totalFail = 0;
                float totalNotApp = 0;
                float totalBlocked = 0;
                float notExecuted = 0;
                float totalTestCases = 0;
                for (int i = 0; i <= 22; i++) {
                    rowIterator.next();
                }
                do {
                    next = rowIterator.next();
                    if (StringUtils.isNotEmpty(getValue(next.getCell(1)))
                            && !getValue(next.getCell(0)).equalsIgnoreCase("S.NO")) {
                        String value = getValue(next.getCell(11));
                        if (StringUtils.isNotEmpty(value)) {
                            if (value.equalsIgnoreCase("success")) {
                                totalPass = totalPass + 1;
                            } else if (value.equalsIgnoreCase("failure")) {
                                totalFail = totalFail + 1;
                            } else if (value.equalsIgnoreCase("notApplicable")) {
                                totalNotApp = totalNotApp + 1;
                            } else if (value.equalsIgnoreCase("blocked")) {
                                totalBlocked = totalBlocked + 1;
                            }
                        } else {
                            notExecuted = notExecuted + 1;
                        }
                    }
                } while (rowIterator.hasNext());
                //to update the status in the index page 
                if (status.equalsIgnoreCase("success")) {
                    totalPass = totalPass + 1;
                } else if (status.equalsIgnoreCase("failure")) {
                    totalFail = totalFail + 1;
                } else if (status.equalsIgnoreCase("notApplicable")) {
                    totalNotApp = totalNotApp + 1;
                } else if (status.equalsIgnoreCase("blocked")) {
                    totalBlocked = totalBlocked + 1;
                } else {
                    notExecuted = notExecuted + 1;
                }
                totalTestCases = totalPass + totalFail + totalNotApp + totalBlocked + notExecuted;
                XSSFSheet 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 (createObject.getName().equals(testSuiteName)) {
                            addCalculationsToIndex(totalPass, totalFail, totalNotApp, totalBlocked, notExecuted,
                                    totalTestCases, next1);
                        }
                    }
                }

                Row r = null;
                if (mySheet.getSheetName().equalsIgnoreCase("Index")) {
                    r = mySheet.createRow(next.getRowNum() - 1);

                } else {
                    r = mySheet.createRow(next.getRowNum() + 1);
                }
                for (int i = 0; i < numCol; i++) {
                    Cell cell = r.createCell(i);
                    cell.setCellValue(cellValue[i]);

                    cell.setCellStyle(tryStyle[i]);
                }
                FileOutputStream fileOut = new FileOutputStream(sb.toString());
                myWorkBook.write(fileOut);
                myInput.close();
                fileOut.close();
            }

        }
    } catch (PhrescoException e) {
        throw new PhrescoException(e);
    } catch (IOException e) {
        throw new PhrescoException(e);
    } catch (InvalidFormatException e) {
        throw new PhrescoException(e);
    }
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

/**
 * import du lieu tu excel/* ww w .j av a  2s .  c om*/
 *
 * @return
 */
public String importFileFromExcel() throws FileNotFoundException, IOException, ParseException {
    List fileInfo = new ArrayList();
    String strReturn = ERROR_PERMISSION;
    //        TechnicalStandard ts = new TechnicalStandard();
    TechnicalStandardDAOHE tshe = new TechnicalStandardDAOHE();
    String err = "";
    Long attachId = Long.parseLong(getRequest().getParameter("attachId"));//get attactId
    VoAttachs att = (VoAttachs) getSession().get("com.viettel.voffice.database.BO.VoAttachs", attachId);//Attachs BO
    if (att == null) {
        fileInfo.add("File not found");
        err += "File not found";
    } else {
        Category item;
        ResourceBundle rb = ResourceBundle.getBundle("config");//get link tuong doi
        String dir = rb.getString("directoryExcel");
        String linkFile = att.getAttachPath();
        linkFile = dir + linkFile;
        createForm.setPath(linkFile);
        InputStream myxls = new FileInputStream(linkFile);//get file excel
        XSSFWorkbook wb = new XSSFWorkbook(myxls);

        XSSFRow row = null;
        String matchingTarget = null;
        XSSFCell productName = null;
        XSSFCell businessTaxCode = null;
        XSSFCell manufactorAddress = null;
        XSSFCell manufactorName = null;
        XSSFCell manufactorTel = null;
        XSSFCell manufactorFax = null;
        XSSFCell manufactorEmail = null;
        XSSFCell nationName = null;
        XSSFCell signer = null;
        XSSFCell assessmentMethod = null;
        XSSFCell annoucementNo = null;

        XSSFCell pushlishDate = null;
        XSSFCell nationCompanyName = null;
        XSSFCell nationCompanyAddress = null;
        try {

            XSSFSheet sheet = wb.getSheetAt(0);
            try {
                //                    XSSFSheet sheet1 = wb.getSheetAt(1);
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                //                    log.error(e.getMessage());
                err += "Khng tm thy Sheet Chi tit sn phm, ";
            }

            try {
                //                    XSSFSheet sheet2 = wb.getSheetAt(2);
            } catch (Exception ex) {
                //                    log.error(e.getMessage());
                LogUtil.addLog(ex);//binhnt sonar a160901
                err += "Khng tm thy Sheet Ch tiu cht lng ch yu, ";
            }

            try {
                //                    XSSFSheet sheet3 = wb.getSheetAt(3);
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                //                    log.error(e.getMessage());
                err += "Khng tm thy Sheet Ch tiu vi sinh vt, ";
            }

            try {
                //                    XSSFSheet sheet4 = wb.getSheetAt(4);
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                //                    log.error(e.getMessage());
                err += "Khng tm thy Sheet Hm lng kim loi nng, ";
            }
            try {
                //                    XSSFSheet sheet5 = wb.getSheetAt(5);
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                //                    log.error(e.getMessage());
                err += "Khng tm thy Sheet Hm lng ha cht, ";
            }
            try {
                //                    XSSFSheet sheet6 = wb.getSheetAt(6);
            } catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                //                    log.error(e.getMessage());
                err += "Khng tm thy Sheet K hoch kim sot cht lng, ";
            }

            if (sheet == null) {
                err += "Khng tm thy Sheet Bn cng b, ";
            } else {
                String sheetName = sheet.getSheetName();
                if (!"Ban_Cong_bo".equals(sheetName)) {
                    err += "Sai tn sheet Bn cng b, ";
                }
            }

            //                XSSFRow firstRow = sheet.getRow(1);
            int rowNums = sheet.getLastRowNum();
            //                UsersDAOHE sdhe = new UsersDAOHE();
            //                SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            row = sheet.getRow(1);
            businessTaxCode = row.getCell((short) 1);
            productName = row.getCell((short) 3);
            row = sheet.getRow(4);
            manufactorName = row.getCell((short) 1);
            manufactorAddress = row.getCell((short) 3);
            row = sheet.getRow(5);
            manufactorTel = row.getCell((short) 1);
            manufactorFax = row.getCell((short) 3);
            row = sheet.getRow(6);
            manufactorEmail = row.getCell((short) 1);
            nationName = row.getCell((short) 3);
            row = sheet.getRow(7);
            nationCompanyName = row.getCell((short) 1);
            nationCompanyAddress = row.getCell((short) 3);

            row = sheet.getRow(10);
            annoucementNo = row.getCell((short) 1);
            pushlishDate = row.getCell((short) 3);
            row = sheet.getRow(11);
            signer = row.getCell((short) 1);
            assessmentMethod = row.getCell((short) 3);
            matchingTarget = "";
            String standardCode;
            for (int i = 12; i < rowNums; i++) {
                row = sheet.getRow(i);
                if (row.getCell((short) 1).toString() != "") {
                    XSSFCell standardCodeCell = row.getCell((short) 1);
                    standardCode = standardCodeCell.getRichStringCellValue().toString();
                    if (tshe.findStandardByCode(standardCode)) {
                        XSSFCell matchingTargetCell = row.getCell((short) 2);
                        matchingTarget += matchingTargetCell.getRichStringCellValue() + ";";
                    } else {
                        err += "Quy chun (quy nh) " + standardCode + " khng chnh xc ! ";
                        break;
                    }
                } else {
                    break;
                }
            }

        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            //                log.error(e.getMessage());
            err += "li tab bn cng b hp quy ";
        }
        if (matchingTarget != "" && matchingTarget != null) {
            matchingTarget = matchingTarget.substring(0, matchingTarget.length() - 1);
        }
        //tab chi tiet san pham
        XSSFCell productNo = null;
        XSSFCell productStatus = null;
        XSSFCell productColor = null;
        XSSFCell productSmell = null;
        XSSFCell productOtherstatus = null;
        XSSFCell productType = null;
        XSSFCell otherTarget = null;
        XSSFCell component = null;
        XSSFCell timeinuse = null;
        XSSFCell useage = null;
        XSSFCell objectInUse = null;
        XSSFCell guideline = null;
        //XSSFCell packageRecipe = null;
        XSSFCell packageMaterial = null;
        XSSFCell productProcess = null;
        XSSFCell counterfeitDistinctive = null;
        XSSFCell origin = null;
        XSSFCell signDate = null;
        XSSFCell signer_productdetails = null;
        XSSFCell chemicalTargetUnwanted = null;
        try {

            XSSFSheet sheet1 = wb.getSheetAt(1);
            if (sheet1 == null) {
                err += "Khng tm thy Sheet Chi tit sn phm, ";

            } else {
                String sheetName = sheet1.getSheetName();
                if (!"Chi_tiet_san_pham".equals(sheetName)) {
                    err += "Sai tn Sheet Chi tit sn phm, ";
                }
            }

            row = sheet1.getRow(1);
            productType = row.getCell((short) 1);
            productNo = row.getCell((short) 3);
            row = sheet1.getRow(4);
            productStatus = row.getCell((short) 1);
            productColor = row.getCell((short) 3);
            row = sheet1.getRow(5);
            productSmell = row.getCell((short) 1);
            productOtherstatus = row.getCell((short) 3);
            row = sheet1.getRow(13);
            otherTarget = row.getCell((short) 1);
            row = sheet1.getRow(14);
            component = row.getCell((short) 1);
            timeinuse = row.getCell((short) 3);
            row = sheet1.getRow(15);
            useage = row.getCell((short) 1);
            objectInUse = row.getCell((short) 3);
            row = sheet1.getRow(16);
            guideline = row.getCell((short) 1);
            packageMaterial = row.getCell((short) 3);
            row = sheet1.getRow(17);
            productProcess = row.getCell((short) 3);
            //packageRecipe = row.getCell((short) 1);
            row = sheet1.getRow(18);
            counterfeitDistinctive = row.getCell((short) 1);
            origin = row.getCell((short) 3);
            row = sheet1.getRow(19);
            signDate = row.getCell((short) 1);
            signer_productdetails = row.getCell((short) 3);
            // bo sung ham luong hoa chat khong mong muon
            XSSFSheet sheet5 = wb.getSheetAt(5);

            int rowNums = sheet5.getLastRowNum();
            do {
                row = sheet5.getRow(rowNums);
                chemicalTargetUnwanted = row.getCell((short) 2);
                rowNums--;
            } while (chemicalTargetUnwanted == null);

            //                chemicalTargetUnwanted = row.getCell((short) 2);
        } catch (Exception ex) {
            LogUtil.addLog(ex);//binhnt sonar a160901
            //                log.error(e.getMessage());
            err += "Li tab chi tit sn phm ";
        }
        // do du lieu vao form
        Long fileId = getRequest().getParameter("fileId") == null ? 0L
                : Long.parseLong(getRequest().getParameter("fileId"));
        Long fileType = getRequest().getParameter("fileType") == null ? 0L
                : Long.parseLong(getRequest().getParameter("fileType"));
        if (fileType > 0L && fileId > 0L) {
            createForm = new FilesForm();
            createForm.setFileType(fileType);
            createForm.setFileId(fileId);
        }
        UsersDAOHE udhe = new UsersDAOHE();
        Users user = udhe.findById(getUserId());

        BusinessDAOHE bdhe = new BusinessDAOHE();
        Business bus = bdhe.findById(user.getBusinessId());

        if (createForm.getFileId() != null && createForm.getFileId() > 0l) {
            FilesDAOHE fdhe = new FilesDAOHE();
            createForm = fdhe.getFilesDetail(createForm.getFileId());
            if (!createForm.getFileType().equals(0L)) {
                ProcedureDAOHE cdhe = new ProcedureDAOHE();
                List lstTTHC = cdhe.getProcedureForChange(createForm.getFileType());
                lstCategory = new ArrayList();
                lstCategory.addAll(lstTTHC);
                lstCategory.add(0,
                        new Procedure(Constants.COMBOBOX_HEADER_VALUE, Constants.COMBOBOX_HEADER_TEXT_SELECT));
                getRequest().setAttribute("lstFileType", lstCategory);

            }
        }

        if (createForm.getFileType() != null && createForm.getFileType() > 0l) {
            ProcedureDAOHE pdhe = new ProcedureDAOHE();
            CategoryDAOHE cdhe = new CategoryDAOHE();
            TechnicalStandardDAOHE tdhe = new TechnicalStandardDAOHE();
            FilesDAOHE fdhe = new FilesDAOHE();
            if (!fileType.equals(0L)) {
                createForm.setFileType(fileType);
            }
            Procedure tthc = pdhe.findById(createForm.getFileType());
            if (tthc != null) {

                lstProductType = cdhe.findAllCategory("SP");
                lstUnit = cdhe.findAllCategory("DVI");

                lstStandard = tdhe.findAllStandard();
                String lstDepts = convertToJSONData(lstStandard, "vietnameseName", "vietnameseName");
                getRequest().setAttribute("lstStandard", lstDepts);

                UserAttachsDAOHE uahe = new UserAttachsDAOHE();
                lstUserAttach = uahe.findAllUserAttach(getUserId());
                String lstUserAttachs = convertToJSONData(lstUserAttach, "attachName", "attachName");
                getRequest().setAttribute("lstUserAttach", lstUserAttachs);
                if (lstUserAttachs.trim().length() > 0) {
                    createForm.setCountUA(1L);
                } else {
                    createForm.setCountUA(0L);
                }
                getRequest().setAttribute("lstProductType", lstProductType);
                getRequest().setAttribute("lstUnit", lstUnit);

                String fileLst = tthc.getFileList();
                getRequest().setAttribute("fileList", com.viettel.common.util.StringUtils.removeHTML(fileLst));
                getRequest().setAttribute("agencyName", getDepartmentName());
                getRequest().setAttribute("fileNameFull", tthc.getName());
                strReturn = tthc.getDescription();
                if (createForm.getAnnouncement() != null) {
                    if (createForm.getAnnouncement().getAnnouncementNo() != null
                            && createForm.getAnnouncement().getAnnouncementNo().length() > 0l) {
                        return strReturn;
                    }
                }
                if (strReturn.equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE01)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.ANNOUNCEMENT_FILE03)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.CONFIRM_FUNC_IMP)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.CONFIRM_FUNC_VN)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.CONFIRM_NORMAL_IMP)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.CONFIRM_NORMAL_VN)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.REC_CONFIRM_NORMAL_IMP)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.RE_ANNOUNCEMENT)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_IMP)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_FUNC_VN)
                        || strReturn.equals(Constants.FILE_DESCRIPTION.RE_CONFIRM_NORMAL_VN)) {
                    String announcementNoStr = fdhe.getReceiptNoNew(getUserId(), getUserLogin(),
                            createForm.getFileType());
                    createForm.setAnnouncement(new AnnouncementForm());
                    createForm.getAnnouncement().setAnnouncementNo(announcementNoStr);
                    // thong tin doanh nghiep
                    createForm.getAnnouncement().setBusinessAddress(bus.getBusinessAddress());
                    createForm.getAnnouncement().setBusinessFax(bus.getBusinessFax());
                    createForm.getAnnouncement().setBusinessName(bus.getBusinessName());
                    createForm.getAnnouncement().setBusinessTelephone(bus.getBusinessTelephone());
                    createForm.getAnnouncement().setBusinessEmail(bus.getUserEmail());
                    createForm.getAnnouncement().setBusinessLicence(bus.getBusinessLicense());

                    // ho so cap lai 7-11
                    createForm.setReIssueForm(new ReIssueFormForm());
                    createForm.getReIssueForm().setBusinessName(bus.getBusinessName());
                    createForm.getReIssueForm().setIdentificationNumber(bus.getBusinessLicense());
                    createForm.getReIssueForm().setAddress(bus.getBusinessAddress());
                    createForm.getReIssueForm().setEmail(bus.getUserEmail());
                    createForm.getReIssueForm().setTelephone(bus.getBusinessTelephone());
                    createForm.getReIssueForm().setFax(bus.getBusinessFax());
                    //set thong tin tu excel

                    try {
                        if (businessTaxCode != null && user.getUserName().equals(businessTaxCode.toString())) {
                            if (matchingTarget != "" && matchingTarget != null) {
                                createForm.getAnnouncement().setMatchingTarget(matchingTarget.toString());
                            }
                            createForm.getAnnouncement().setProductName(productName.toString());
                            createForm.getAnnouncement().setManufactureAddress(manufactorAddress.toString());
                            createForm.getAnnouncement().setManufactureName(manufactorName.toString());
                            createForm.getAnnouncement().setManufactureTel(manufactorTel.toString());
                            createForm.getAnnouncement().setManufactureFax(manufactorFax.toString());
                            createForm.getAnnouncement().setManufactureEmail(manufactorEmail.toString());
                            createForm.getAnnouncement().setNationName(nationName.toString());
                            createForm.getAnnouncement().setSigner(signer.toString());
                            createForm.getAnnouncement()
                                    .setNationCompanyAddress(nationCompanyAddress.toString());
                            createForm.getAnnouncement().setNationCompanyName(nationCompanyName.toString());
                            createForm.getAnnouncement().setAssessmentMethod(assessmentMethod.toString());
                            if (pushlishDate.toString() != null && pushlishDate.toString().length() > 0) {
                                createForm.getAnnouncement().setPublishDate(DateTimeUtils
                                        .convertStringToTime(pushlishDate.toString(), "dd/MM/yyyy"));
                            }
                            createForm.getAnnouncement().setAnnouncementNo(annoucementNo.toString());
                            //tab thong tin chi tiet
                            createForm.setDetailProduct(new DetailProductForm());
                            createForm.getDetailProduct().setProductNo(productNo.toString());
                            createForm.getDetailProduct().setProductStatus(productStatus.toString());
                            createForm.getDetailProduct().setProductColor(productColor.toString());
                            createForm.getDetailProduct().setProductSmell(productSmell.toString());
                            createForm.getDetailProduct().setProductOtherStatus(productOtherstatus.toString());

                            item = cdhe.findCategoryByName("SP", productType.toString());
                            if (item != null) {
                                createForm.getDetailProduct().setProductType(item.getCategoryId());
                            } else {
                                err += "Danh mc " + productType.toString() + " khng chnh xc, ";
                            }

                            createForm.getDetailProduct().setOtherTarget(otherTarget.toString());
                            createForm.getDetailProduct().setComponents(component.toString());
                            createForm.getDetailProduct().setTimeInUse(timeinuse.toString());
                            createForm.getDetailProduct().setUseage(useage.toString());
                            createForm.getDetailProduct().setObjectUse(objectInUse.toString());
                            createForm.getDetailProduct().setGuideline(guideline.toString());
                            //createForm.getDetailProduct().setPackageRecipe(packageRecipe.toString());
                            createForm.getDetailProduct().setPackateMaterial(packageMaterial.toString());
                            createForm.getDetailProduct().setProductionProcess(productProcess.toString());
                            createForm.getDetailProduct()
                                    .setCounterfeitDistinctive(counterfeitDistinctive.toString());
                            createForm.getDetailProduct().setOrigin(origin.toString());
                            if (signDate.toString() != null && signDate.toString().length() > 0) {
                                createForm.getDetailProduct().setSignDate(
                                        DateTimeUtils.convertStringToTime(signDate.toString(), "dd/MM/yyyy"));
                            }
                            createForm.getDetailProduct().setSigner(signer_productdetails.toString());
                            createForm.getDetailProduct()
                                    .setChemicalTargetUnwanted(chemicalTargetUnwanted.toString());
                            createForm.setStatusExcel(
                                    err += "Thm mi bn cng b hp quy thnh cng ");
                        } else {
                            createForm.setStatusExcel(err += "M s thu khng chnh xc ");
                        }
                    } catch (Exception ex) {
                        //                            log.error(parseException);
                        LogUtil.addLog(ex);//binhnt sonar a160901
                        createForm.setStatusExcel(
                                err += "Thm mi bn cng b hp quy khng thnh cng ");
                    }
                }
            }
        }
    }
    CategoryDAOHE ctdhe = new CategoryDAOHE();
    Category cate = ctdhe.findCategoryByTypeAndCode("SP", "TPCN");
    Category cateTL = ctdhe.findCategoryByTypeAndCode("SP", "TL");
    List<Category> cate1 = ctdhe.findCategoryByTypeAndCodeNew("SP", "DBT");
    String dbtId = "";
    for (int i = 0; i < cate1.size(); i++) {
        dbtId += cate1.get(i).getCategoryId().toString() + ";";
    }
    Long tpcnId = cate.getCategoryId();
    Long tlId = cateTL.getCategoryId();
    FeeDAOHE fdhe1 = new FeeDAOHE();
    Fee findfee1 = fdhe1.findFeeByCode("TPDB");
    Long priceTPDB = findfee1.getPrice();
    Fee findfee2 = fdhe1.findFeeByCode("TPCN");
    Long priceTPCN = findfee2.getPrice();
    Fee findfee3 = fdhe1.findFeeByCode("TPK");
    Long priceETC = findfee3.getPrice();
    getRequest().setAttribute("dbtId", dbtId);
    getRequest().setAttribute("tpcnId", tpcnId);
    getRequest().setAttribute("tlId", tlId);
    getRequest().setAttribute("priceTPCN", priceTPCN);
    getRequest().setAttribute("priceTPDB", priceTPDB);
    getRequest().setAttribute("priceETC", priceETC);

    return strReturn;
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

/**
 * load mainly target tu excel//from  ww  w. j av a  2s  . com
 *
 * @return
 */
public String loadMainlyTargetExcel() throws FileNotFoundException, IOException {
    // mainly target
    Category item = new Category();
    String linkFile = getRequest().getParameter("path");
    String fileError = "";
    List customInfo = new ArrayList();
    InputStream myxls = new FileInputStream(linkFile);//get file excel
    XSSFWorkbook wb = new XSSFWorkbook(myxls);
    List<MainlyTarget> lstMainlyTarget = null;
    try {
        XSSFSheet sheet2 = wb.getSheetAt(2);
        if (sheet2 == null) {
            fileError += "Khng tm thy Sheet Ch tiu cht lng ch yu, ";
        } else {
            String sheetName = sheet2.getSheetName();
            if (!"Chi_tieu_chat_luong_chu_yeu".equals(sheetName)) {
                fileError += "Sai tn Sheet Ch tiu cht lng ch yu, ";
            }
        }

        XSSFRow row;
        int rowNums2 = sheet2.getLastRowNum();
        lstMainlyTarget = new ArrayList<MainlyTarget>();
        CategoryDAOHE cdhed = new CategoryDAOHE();

        for (int i = 2; i < rowNums2; i++) {
            row = sheet2.getRow(i);
            if (row.getCell((short) 1) != null && row.getCell((short) 1).toString().trim() != "") {
                MainlyTarget temp = new MainlyTarget();
                XSSFCell targetName = row.getCell((short) 1);
                XSSFCell unitId = row.getCell((short) 2);
                XSSFCell publishLevel = row.getCell((short) 3);
                XSSFCell meetLevel = row.getCell((short) 4);
                item = cdhed.findCategoryByName("DVI", unitId.toString());
                if (item != null) {
                    temp.setMeetLevel(meetLevel.toString());
                    temp.setTargetName(targetName.toString());
                    temp.setUnitId(item.getCategoryId().toString());
                    temp.setPublishLevel(publishLevel.toString());
                    lstMainlyTarget.add(temp);
                } else {
                    fileError += "Danh mc n v " + unitId.toString() + " khng chnh xc, ";
                }
            } else {
                break;
            }
        }
        fileError += "Thm mi cc ch tiu cht lng ch yu thnh cng ";
        customInfo.add(fileError);
    } catch (Exception ex) {
        fileError += "Thm mi cc ch tiu cht lng ch yu khng thnh cng ";
        customInfo.add(fileError);
        //            log.error(e.getMessage());
        LogUtil.addLog(ex);//binhnt sonar a160901
    }
    jsonDataGrid.setCustomInfo(customInfo);
    jsonDataGrid.setItems(lstMainlyTarget);
    return GRID_DATA;
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

/**
 * load product target tu excel/*from ww w. j a v a 2 s  .co m*/
 *
 * @return
 */
public String loadProductTargetExcel() throws FileNotFoundException, IOException {

    Category item = new Category();
    String linkFile = getRequest().getParameter("path");
    String fileError = "";
    List customInfo = new ArrayList();
    InputStream myxls = new FileInputStream(linkFile);//get file excel
    XSSFWorkbook wb = new XSSFWorkbook(myxls);
    List<ProductTarget> lstProductTarget = null;
    try {
        XSSFSheet sheet3 = wb.getSheetAt(3);
        if (sheet3 == null) {
            fileError += "Khng tm thy Sheet Ch tiu vi sinh vt, ";
        } else {
            String sheetName = sheet3.getSheetName();
            if (!"Chi_tieu_vi_sinh_vat".equals(sheetName)) {
                fileError += "Sai tn Sheet Ch tiu vi sinh vt, ";
            }
        }
        XSSFRow row;
        int rowNums3 = sheet3.getLastRowNum();
        lstProductTarget = new ArrayList<ProductTarget>();
        CategoryDAOHE cdhed = new CategoryDAOHE();
        // vi sinh vat
        for (int i = 2; i < rowNums3; i++) {
            row = sheet3.getRow(i);
            if (row.getCell((short) 1) != null && !"".equals(row.getCell((short) 1).toString().trim())) {
                ProductTarget temp = new ProductTarget();
                XSSFCell targetName = row.getCell((short) 1);
                XSSFCell unitId = row.getCell((short) 2);
                XSSFCell maxLevel = row.getCell((short) 3);
                item = cdhed.findCategoryByName("DVI", unitId.toString().trim());
                if (item != null) {
                    temp.setTargetName(targetName.toString());
                    temp.setUnitId(item.getCategoryId().toString());
                    temp.setMaxLevel(maxLevel.toString());
                    temp.setTargetType(1l);
                    lstProductTarget.add(temp);
                } else {
                    fileError += "Danh mc n v " + unitId.toString() + " khng chnh xc, ";
                }
            } else {
                break;
            }

        }
        //kim loai nang

        XSSFSheet sheet4 = wb.getSheetAt(4);
        if (sheet4 == null) {
            fileError += "Khng tm thy Sheet Hm lng kim loi nng, ";
        } else {
            String sheetName2 = sheet4.getSheetName();
            if (!"Ham_luong_kim_loai_nang".equals(sheetName2)) {
                fileError += "Sai tn Sheet Hm lng kim loi nng, ";
            }
        }
        int rowNums4 = sheet4.getLastRowNum();
        for (int i = 2; i < rowNums4; i++) {
            row = sheet4.getRow(i);
            if (row.getCell((short) 1) != null && !"".equals(row.getCell((short) 1).toString().trim())) {
                ProductTarget temp = new ProductTarget();
                XSSFCell targetName = row.getCell((short) 1);
                XSSFCell unitId = row.getCell((short) 2);
                XSSFCell maxLevel = row.getCell((short) 3);
                item = cdhed.findCategoryByName("DVI", unitId.toString().trim());
                if (item != null) {
                    temp.setTargetName(targetName.toString());
                    temp.setUnitId(item.getCategoryId().toString());
                    temp.setMaxLevel(maxLevel.toString());
                    temp.setTargetType(2l);
                    lstProductTarget.add(temp);
                } else {
                    fileError += "Danh mc n v " + unitId.toString() + " khng chnh xc, ";
                }
            } else {
                break;
            }
        }

        //hoa chat khong mong muon
        XSSFSheet sheet5 = wb.getSheetAt(5);
        if (sheet5 == null) {
            fileError += "Khng tm thy Sheet Hm lng ha cht khng mong mun, ";
        } else {
            String sheetName1 = sheet5.getSheetName();

            if (!"Ham_luong_hoa_chat".equals(sheetName1)) {
                fileError += "Sai tn Sheet Hm lng ha cht khng mong mun, ";
            }
        }
        int rowNums5 = sheet5.getLastRowNum();
        for (int i = 2; i < rowNums5; i++) {
            row = sheet5.getRow(i);
            if (row.getCell((short) 1) != null && !"".equals(row.getCell((short) 1).toString().trim())) {
                ProductTarget temp = new ProductTarget();
                XSSFCell targetName = row.getCell((short) 1);
                XSSFCell unitId = row.getCell((short) 2);
                XSSFCell maxLevel = row.getCell((short) 3);
                item = cdhed.findCategoryByName("DVI", unitId.toString().trim());
                if (item != null) {
                    temp.setTargetName(targetName.toString());
                    temp.setUnitId(item.getCategoryId().toString());
                    temp.setMaxLevel(maxLevel.toString());
                    temp.setTargetType(3l);
                    lstProductTarget.add(temp);
                } else {
                    fileError += "Danh mc n v " + unitId.toString() + " khng chnh xc, ";
                }
            } else {
                break;
            }
        }
        fileError += "Thm mi cc ch tiu vi sinh vt, hm lng kim loi nng, hm lng ha cht khng mong mun thnh cng ";
        customInfo.add(fileError);

    } catch (Exception ex) {
        fileError += "Thm mi cc ch tiu vi sinh vt, hm lng kim loi nng, hm lng ha cht khng mong mun khng thnh cng ";
        customInfo.add(fileError);
        //            log.error(e.getMessage());
        LogUtil.addLog(ex);//binhnt sonar a160901
    }
    jsonDataGrid.setCustomInfo(customInfo);
    jsonDataGrid.setItems(lstProductTarget);
    return GRID_DATA;
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

/**
 * load quality control plan excel/*w  ww  . j a v a2  s . c o  m*/
 *
 * @return
 */
public String loadQualityControlsExcel() throws FileNotFoundException, IOException {
    // mainly target
    //        Category item = new Category();
    String linkFile = getRequest().getParameter("path");
    String fileError = "";
    List customInfo = new ArrayList();
    InputStream myxls = new FileInputStream(linkFile);//get file excel
    XSSFWorkbook wb = new XSSFWorkbook(myxls);
    List<QualityControlPlan> lstQualityControl = null;
    try {
        XSSFSheet sheet6 = wb.getSheetAt(6);
        if (sheet6 == null) {
            fileError += "Khng tm thy Sheet K hoch kim sot, ";
        } else {
            String sheetName1 = sheet6.getSheetName();

            if (!"Ke_Hoach_Kiem_soat".equals(sheetName1)) {
                fileError += "Khng tm thy Sheet K hoch kim sot, ";
            }
        }
        XSSFRow row;
        int rowNums6 = sheet6.getLastRowNum();
        lstQualityControl = new ArrayList<QualityControlPlan>();
        //            CategoryDAOHE cdhed = new CategoryDAOHE();

        for (int i = 2; i < rowNums6; i++) {
            row = sheet6.getRow(i);
            if (row.getCell((short) 1).toString().trim() != "") {
                QualityControlPlan temp = new QualityControlPlan();
                XSSFCell processDetails = row.getCell((short) 1);
                XSSFCell controlTarget = row.getCell((short) 2);
                XSSFCell technicalRegulation = row.getCell((short) 3);
                XSSFCell patternFrequence = row.getCell((short) 4);
                XSSFCell testDevice = row.getCell((short) 5);
                XSSFCell testMethod = row.getCell((short) 6);
                //                    XSSFCell noteForm = row.getCell((short) 7);
                XSSFCell note = row.getCell((short) 8);
                temp.setProductProcessDetail(processDetails.toString());
                temp.setControlTarget(controlTarget.toString());
                temp.setTechnicalRegulation(technicalRegulation.toString());
                temp.setPatternFrequence(patternFrequence.toString());
                temp.setTestDevice(testDevice.toString());
                temp.setTestMethod(testMethod.toString());
                temp.setNote(note.toString());
                temp.setNoteForm(note.toString());
                lstQualityControl.add(temp);
            } else {
                break;
            }

        }
        fileError = "Thm mi k hoch kim sot cht lng thnh cng ";
        customInfo.add(fileError);
    } catch (Exception ex) {
        fileError = "Thm mi k hoch kim sot cht lng khng thnh cng ";
        customInfo.add(fileError);
        //            log.error(e.getMessage());
        LogUtil.addLog(ex);//binhnt sonar a160901
    }

    jsonDataGrid.setCustomInfo(customInfo);
    jsonDataGrid.setItems(lstQualityControl);
    return GRID_DATA;
}

From source file:com.yanglb.utilitys.codegen.core.reader.BaseModelReader.java

License:Apache License

protected T onReader(XSSFSheet sheet, Class<T> cls) throws CodeGenException {
    T model = null;//from w  ww . j a va  2s  .  c  o m
    try {
        model = cls.newInstance();
        ((BaseModel) model).setSheetName(sheet.getSheetName());
        ((BaseModel) model).setExcelFileName(this.excelFile);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new CodeGenException(e.getMessage());
    }
    return model;
}

From source file:com.yanglb.utilitys.codegen.core.reader.BaseReader.java

License:Apache License

/**
 * ?//from   w  w w . j  a  va2 s .co  m
 * @throws CodeGenException 
 */
private void doReader() throws CodeGenException {
    // 
    XSSFWorkbook wb = null;
    try {
        // jar??new File
        if (this.excelFile.startsWith("jar:")) {
            String path = this.excelFile.substring(4);
            InputStream is = this.getClass().getResourceAsStream(path);
            wb = new XSSFWorkbook(is);
        } else {
            File file = new File(this.excelFile);
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            wb = new XSSFWorkbook(in);
        }

        // ?
        HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);

        // ??
        if (this.sheets == null || this.sheets.length == 0) {
            // ?
            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
                XSSFSheet sheet = wb.getSheetAt(i);

                // ???Sheet
                if (!this.isReadable(sheet.getSheetName())) {
                    continue;
                }
                this.results.add(this.onReader(sheet));
            }
        } else {
            // ?Sheet
            for (String sheetName : this.sheets) {
                XSSFSheet sheet = wb.getSheet(sheetName);
                if (sheet == null) {
                    throw new CodeGenException(String.format(MsgUtility.getString("E_004"), sheetName));
                }
                this.results.add(this.onReader(sheet));
            }
        }
    } catch (FileNotFoundException e) {
        // ???
        throw new CodeGenException(e.getMessage());
    } catch (UnImplementException e) {
        this.results.clear();
        e.printStackTrace();
    } catch (IOException e) {
        throw new CodeGenException(MsgUtility.getString("E_005"));
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.yanglb.utilitys.codegen.core.reader.impl.TableReaderImpl.java

License:Apache License

/**
 * ?DBSheet//from w w  w. j  av  a  2 s .co  m
 * @throws CodeGenException
 */
@Override
protected TableModel onReader(XSSFSheet sheet) throws CodeGenException {
    TableModel model = super.onReader(sheet, TableModel.class);

    // KEY
    String[] keys = null;
    List<String> listKey = new ArrayList<String>();
    Map<String, String> curValue = null; // ?

    for (int rowNo = this.startRowNo; rowNo <= sheet.getLastRowNum(); rowNo++) {
        XSSFRow row = sheet.getRow(rowNo);
        // KEY
        if (rowNo == this.startRowNo) {
            keys = new String[row.getLastCellNum()];
        } else {
            curValue = new HashMap<String, String>();
        }

        // ? ??
        boolean allBlank = true;

        // ?
        if (row == null) {
            throw new CodeGenException(String.format("error: sheet(%s), row(%d)", sheet.getSheetName(), rowNo));
        }
        for (int colNo = this.startColNo; colNo < row.getLastCellNum(); colNo++) {
            XSSFCell cell = row.getCell(colNo);
            if (cell == null) {
                throw new CodeGenException(String.format("error: sheet(%s), row(%d), col(%d)",
                        sheet.getSheetName(), rowNo, colNo));
            }
            if (cell.getCellType() != XSSFCell.CELL_TYPE_BLANK
                    && cell.getCellType() != XSSFCell.CELL_TYPE_ERROR) {
                allBlank = false;
            }
            String value = this.getCellStringValue(cell);

            // KEY
            if (rowNo == this.startRowNo) {
                if (StringUtility.isNullOrEmpty(value) || cell.getCellType() == XSSFCell.CELL_TYPE_BLANK
                        || "-".equals(value)) {
                    // /
                    continue;
                }
                keys[colNo] = value;
                listKey.add(value);
            } else {
                if (colNo >= keys.length)
                    continue;

                // 
                String key = keys[colNo];
                if (!StringUtility.isNullOrEmpty(key)) {
                    curValue.put(keys[colNo], value);
                }
            }
        }

        // ?
        if (!allBlank && curValue != null) {
            model.insert(curValue);
        }
    }

    // 
    model.setColumns((String[]) listKey.toArray(new String[0]));
    return model;
}

From source file:comparator.Comparator.java

public static void transcoding_Map_HUG() throws IOException {
    //Get the input files
    FileInputStream mvcFile = new FileInputStream(new File(
            "\\\\hes-nas-drize.hes.adhes.hesge.ch\\home\\luc.mottin\\Documents\\Expand\\MVC2.0\\Informal_epSOS-MVC_V2_0_(DRAFT)_03.xlsx"));
    //Get the workbook instance for XLS file 
    XSSFWorkbook mvcWorkbook = new XSSFWorkbook(mvcFile);
    XSSFSheet mvcSheet;
    Iterator<Row> mvcRowIterator;
    String mvcSheetName;/*from  w  ww.j ava2 s . c  o  m*/
    int mvcCol;
    boolean mvcColFound;
    Row mvcRow;
    Row mvcRow2;
    Iterator<Cell> mvcCellIterator;
    boolean statusOK = false;

    //OUTPUT
    String code_src;
    String code_dest;
    String name_dest = "";
    String value_set_name_dest = "";
    String status = "none";
    String value_set_name_source = "";
    String value_set_oid_dest = "";
    String parent_system_code_dest = "";
    String parent_system_oid_dest = "";
    String comment = "";
    String map_level = "0";
    String review = "0";
    String version = "";

    //Prepare the output file
    Writer csvW = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
            "\\\\hes-nas-drize.hes.adhes.hesge.ch\\home\\luc.mottin\\Documents\\Expand\\Map_HUG\\map_hug_to_mvc_2.0.csv"),
            "UTF-8"));
    csvW.write('\ufeff');
    csvW.write(
            "code_src;code_dest;name_dest;value_set_name_dest;status;value_set_name_source;value_set_oid_dest;parent_system_code_dest;parent_system_oid_dest;comment;map_level;review;version;");
    csvW.write("\n");

    //Read csv map
    String map = "\\\\hes-nas-drize.hes.adhes.hesge.ch\\home\\luc.mottin\\Documents\\Expand\\Map_HUG\\map_hug_to_mvc_1_9.csv";
    try {
        BufferedReader br = new BufferedReader(new FileReader(map));
        String line = "";
        String csvSplitBy = ";";
        String[] maLigne;

        //jump over the first line
        br.readLine();
        //pour chaque ligne de la map
        while ((line = br.readLine()) != null) {
            statusOK = false;

            maLigne = line.split(csvSplitBy);
            code_src = maLigne[0];
            code_dest = maLigne[1];

            //Get the sheet from the MTC workbook
            for (int i = 0; i < mvcWorkbook.getNumberOfSheets(); i++) {
                mvcSheet = mvcWorkbook.getSheetAt(i);

                //Get iterator to all the rows in current MTC sheet
                mvcRowIterator = mvcSheet.iterator();

                //Get the name of MTTC sheet, compare them MAP entries
                //MVC data files are called "epSOSsheetName"
                mvcSheetName = mvcSheet.getSheetName();

                //And process the file matching to find the good sheet
                if (mvcSheetName.equals(maLigne[3])) {
                    value_set_name_dest = mvcSheetName;
                    value_set_name_source = maLigne[5];

                    mvcCol = 0;
                    mvcColFound = false;

                    while (mvcRowIterator.hasNext()) {
                        mvcRow = mvcRowIterator.next();
                        mvcRow2 = mvcRow;

                        if (mvcColFound == false) {
                            mvcCellIterator = mvcRow.cellIterator();

                            while (mvcCellIterator.hasNext()) {
                                Cell mvcCell = mvcCellIterator.next();

                                if (mvcCell.getCellType() == 1
                                        && (mvcCell.getStringCellValue().equals("Parent Code System:"))) {
                                    mvcCol = mvcCell.getColumnIndex() + 1;
                                    mvcRow.getCell(mvcCol, Row.CREATE_NULL_AS_BLANK)
                                            .setCellType(Cell.CELL_TYPE_STRING);
                                    parent_system_code_dest = mvcRow.getCell(mvcCol).getStringCellValue()
                                            .trim();
                                }
                                if (mvcCell.getCellType() == 1
                                        && (mvcCell.getStringCellValue().equals("OID Parent Code System:"))) {
                                    mvcCol = mvcCell.getColumnIndex() + 1;
                                    mvcRow.getCell(mvcCol, Row.CREATE_NULL_AS_BLANK)
                                            .setCellType(Cell.CELL_TYPE_STRING);
                                    parent_system_oid_dest = mvcRow.getCell(mvcCol).getStringCellValue().trim();
                                }
                                if (mvcCell.getCellType() == 1
                                        && (mvcCell.getStringCellValue().equals("epSOS OID:"))) {
                                    mvcCol = mvcCell.getColumnIndex() + 1;
                                    mvcRow.getCell(mvcCol, Row.CREATE_NULL_AS_BLANK)
                                            .setCellType(Cell.CELL_TYPE_STRING);
                                    value_set_oid_dest = mvcRow.getCell(mvcCol).getStringCellValue().trim();
                                }
                                if (mvcCell.getCellType() == 1
                                        && (mvcCell.getStringCellValue().equals("version:"))) {
                                    mvcCol = mvcCell.getColumnIndex() + 1;
                                    mvcRow.getCell(mvcCol, Row.CREATE_NULL_AS_BLANK)
                                            .setCellType(Cell.CELL_TYPE_STRING);
                                    version = mvcRow.getCell(mvcCol).getStringCellValue().trim();
                                }

                                if (mvcCell.getCellType() == 1
                                        && (mvcCell.getStringCellValue().equals("epSOS Code")
                                                || mvcCell.getStringCellValue().equals("Code"))) {
                                    mvcCol = mvcCell.getColumnIndex();
                                    mvcColFound = true;
                                    break;
                                }
                            }
                        } else {
                            mvcRow.getCell(mvcCol, Row.CREATE_NULL_AS_BLANK).setCellType(Cell.CELL_TYPE_STRING);
                            if (mvcRow.getCell(mvcCol).getStringCellValue().trim().equals(code_dest)) {
                                statusOK = true;
                                mvcRow2.getCell(mvcCol + 1, Row.CREATE_NULL_AS_BLANK)
                                        .setCellType(Cell.CELL_TYPE_STRING);
                                name_dest = mvcRow2.getCell(mvcCol + 1).getStringCellValue().trim();
                                break;
                            }

                        }
                    }
                    if (statusOK == true) {
                        break;
                    } else {
                        parent_system_code_dest = "";
                        parent_system_oid_dest = "";
                        value_set_oid_dest = "";
                        version = "";
                    }
                }
            }

            if (statusOK != true) {
                //TO CHECK MANUALY
                status = "manual";
                name_dest = maLigne[2];
                comment = "mvc2.0 no hug code";
            }

            //Write the mapping
            csvW.write(code_src + ";" + code_dest + ";" + name_dest + ";" + value_set_name_dest + ";" + status
                    + ";" + value_set_name_source + ";" + value_set_oid_dest + ";" + parent_system_code_dest
                    + ";" + parent_system_oid_dest + ";" + comment + ";" + map_level + ";" + review + ";"
                    + version + ";");
            csvW.write("\n");
            //reset status
            status = "none";
            comment = "";

        }

        br.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    csvW.flush();
    csvW.close();

}