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

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

Introduction

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

Prototype

@Override
public int getLastRowNum() 

Source Link

Document

Gets the number last row on the sheet.

Usage

From source file:egovframework.oe1.cms.cmm.web.EgovOe1DicGovTermController.java

License:Apache License

/**
*   ? /*from   ww  w .  j ava 2s  . c om*/
* @param ComDefaultVO - ?    VO
* @param model
* @return "forward:/cms/cmm/selectDicGovTermList.do"
* @exception Exception
*/
@RequestMapping("/cms/cmm/addDicGovTermExcelOK.do")
public String addDicGovTermExcelRegister(final HttpServletRequest request,
        @ModelAttribute("egovOe1DicGovTermVO") EgovOe1DicGovTermVO egovOe1DicGovTermVO,
        BindingResult bindingResult, Model model, SessionStatus status) throws Exception {

    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    if (bindingResult.hasErrors()) {
        model.addAttribute("egovOe1DicGovTermVO", egovOe1DicGovTermVO);
        return "/cms/cmm/addDicGovTermExcel";
    }

    model.addAttribute("searchMode", egovOe1DicGovTermVO);

    //
    EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    try {

        final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
        final Map<String, MultipartFile> files = multiRequest.getFileMap();

        Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator();
        MultipartFile file;

        String filePath = "";

        while (itr.hasNext()) {
            Entry<String, MultipartFile> entry = itr.next();

            file = entry.getValue();
            if (!"".equals(file.getOriginalFilename())) {

                String _storePath = propertyService.getString("Globals.fileStorePath");

                File saveFolder = new File(_storePath);
                if (!saveFolder.exists() || saveFolder.isFile()) {
                    saveFolder.mkdirs();
                }

                String orginFileName = file.getOriginalFilename();
                int _index = orginFileName.lastIndexOf(".");
                String fileName = orginFileName.substring(0, _index);
                String fileExt = orginFileName.substring(_index + 1);
                long _size = file.getSize();

                if (!"".equals(orginFileName)) {
                    filePath = _storePath + File.separator + "EgovStandardTermStatus.xls";
                    file.transferTo(new File(filePath));
                }

                //System.out.println("?=====>"+orginFileName);
                //System.out.println("?=====>"+fileName);
                //System.out.println("?=====>"+fileExt);
                //System.out.println("??=====>"+_size);
                //System.out.println("??=====>"+filePath);

                if ((fileExt.equals("xls") || fileExt.equals("xlsx"))
                        && (filePath != null && !"".equals(filePath))) {

                    HSSFWorkbook wbT = excelService.loadWorkbook(filePath);
                    HSSFSheet sheetT = wbT.getSheet(wbT.getSheetName(0));

                    HSSFRow rowValue = sheetT.getRow(1);
                    HSSFCell cellValue1 = rowValue.getCell(1); //
                    HSSFCell cellValue2 = rowValue.getCell(2); //
                    HSSFCell cellValue3 = rowValue.getCell(3); //?
                    HSSFCell cellValue4 = rowValue.getCell(4); //?
                    HSSFCell cellValue5 = rowValue.getCell(5); //?
                    HSSFCell cellValue6 = rowValue.getCell(6); //?
                    HSSFCell cellValue8 = rowValue.getCell(8); //?
                    String AdministWordSe = (cellValue1 + "").trim();
                    String AdministWordNm = (cellValue2 + "").trim();
                    String AdministWordEngNm = (cellValue3 + "").trim();
                    String AdministWordAbrv = (cellValue4 + "").trim();
                    String AdministWordDc = (cellValue5 + "").trim();
                    String ThemaRelm = (cellValue6 + "").trim();
                    String UseAt = (cellValue8 + "").trim();

                    //System.out.println("AdministWordSe====>"+AdministWordSe);
                    //System.out.println("AdministWordNm====>"+AdministWordNm);
                    //System.out.println("AdministWordEngNm====>"+AdministWordEngNm);
                    //System.out.println("AdministWordAbrv====>"+AdministWordAbrv);
                    //System.out.println("AdministWordDc====>"+AdministWordDc);
                    //System.out.println("ThemaRelm====>"+ThemaRelm);
                    //System.out.println("UseAt====>"+UseAt);

                    if (!"".equals(AdministWordSe) || !"".equals(AdministWordNm)
                            || !"?".equals(AdministWordEngNm)
                            || !"?".equals(AdministWordAbrv) || !"?".equals(AdministWordDc)
                            || !"?".equals(ThemaRelm) || !"?".equals(UseAt)) {
                        model.addAttribute("resultMsg",
                                " EXCEL ?? .   .");
                        return "/cms/cmm/EgovDicGovTermExcelRegist";
                    }

                    List<EgovOe1DicGovTermVO> dicGovTermListVO = new ArrayList<EgovOe1DicGovTermVO>();
                    for (int i = 2; i <= sheetT.getLastRowNum(); i++) {
                        HSSFRow row1 = sheetT.getRow(i);

                        HSSFCell cell1 = row1.getCell(1); //(/??)
                        HSSFCell cell2 = row1.getCell(2); //
                        HSSFCell cell3 = row1.getCell(3); //?
                        HSSFCell cell4 = row1.getCell(4); //?
                        HSSFCell cell5 = row1.getCell(5); //
                        HSSFCell cell6 = row1.getCell(6); //?
                        HSSFCell cell8 = row1.getCell(8); //

                        AdministWordSe = (cell1 + "").trim();
                        AdministWordNm = (cell2 + "").trim();
                        AdministWordEngNm = (cell3 + "").trim();
                        AdministWordAbrv = (cell4 + "").trim();
                        AdministWordDc = (cell5 + "").trim();
                        ThemaRelm = (cell6 + "").trim();
                        UseAt = (cell8 + "").trim();

                        if (("".equals(AdministWordSe) || "??".equals(AdministWordSe))
                                && (!"".equals(AdministWordSe) && AdministWordSe != null)
                                && (!"".equals(AdministWordNm) && AdministWordNm != null)
                                && (!"".equals(AdministWordEngNm) && AdministWordEngNm != null)
                                && (!"".equals(AdministWordAbrv) && AdministWordAbrv != null)
                                && (!"".equals(AdministWordDc) && AdministWordDc != null)) {
                            EgovOe1DicGovTermVO egovOe1DicGovTermExcelVO = new EgovOe1DicGovTermVO();
                            if ("".equals(AdministWordSe)) {
                                egovOe1DicGovTermExcelVO.setAdministWordSe("001");
                            } else {
                                egovOe1DicGovTermExcelVO.setAdministWordSe("002");
                            }
                            egovOe1DicGovTermExcelVO.setAdministWordNm(AdministWordNm);
                            egovOe1DicGovTermExcelVO.setAdministWordEngNm(AdministWordEngNm);
                            egovOe1DicGovTermExcelVO.setAdministWordAbrv(AdministWordAbrv);
                            egovOe1DicGovTermExcelVO.setAdministWordDc(AdministWordDc);
                            egovOe1DicGovTermExcelVO.setThemaRelm(ThemaRelm);
                            if (UseAt.equals("")) {
                                egovOe1DicGovTermExcelVO.setUseAt("Y");
                            } else {
                                egovOe1DicGovTermExcelVO.setUseAt("N");
                            }
                            egovOe1DicGovTermExcelVO.setFrstRegisterId(user.getMberId());
                            dicGovTermListVO.add(egovOe1DicGovTermExcelVO);

                            for (int kk = 0; kk < dicGovTermListVO.size(); kk++) {
                                if (kk > 1) {
                                    if (dicGovTermListVO.get(kk - 1).getAdministWordNm().trim()
                                            .equals(AdministWordNm)
                                            && dicGovTermListVO.get(kk - 1).getAdministWordEngNm().trim()
                                                    .equals(AdministWordEngNm)
                                            && dicGovTermListVO.get(kk - 1).getAdministWordAbrv().trim()
                                                    .equals(AdministWordAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? , ?, ?? . ?    .");
                                        return "/cms/cmm/EgovDicGovTermExcelRegist";
                                    }
                                } else if (kk == 1) {
                                    if (dicGovTermListVO.get(kk - 1).getAdministWordNm().trim()
                                            .equals(AdministWordNm)
                                            && dicGovTermListVO.get(kk - 1).getAdministWordEngNm().trim()
                                                    .equals(AdministWordEngNm)
                                            && dicGovTermListVO.get(kk - 1).getAdministWordAbrv().trim()
                                                    .equals(AdministWordAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? , ?, ?? . ?    .");
                                        return "/cms/cmm/EgovDicGovTermExcelRegist";
                                    }
                                }
                            }

                        } else {
                            if (!"".equals(AdministWordSe) && !"??".equals(AdministWordSe)) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "???  ? /??  . ?    .");
                            }
                            if ("".equals(AdministWordSe) || AdministWordSe == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "???  ? . ?    .");
                            }
                            if ("".equals(AdministWordNm) || AdministWordNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            if ("".equals(AdministWordEngNm) || AdministWordEngNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ?? . ?    .");
                            }
                            if ("".equals(AdministWordAbrv) || AdministWordAbrv == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            if ("".equals(AdministWordDc) || AdministWordDc == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            return "/cms/cmm/EgovDicGovTermExcelRegist";
                        }
                    }

                    // ? ??    .
                    egovOe1DicGovTermService.deleteExcelDicGovTerm();

                    List<EgovOe1DicGovTermVO> list = dicGovTermListVO;

                    for (EgovOe1DicGovTermVO dicGovTermVo : list) {
                        egovOe1DicGovTermService.insertExcelDicGovTerm(dicGovTermVo);
                    }

                } else {
                    model.addAttribute("resultMsg",
                            " EXCEL ?? .   .");
                    return "/cms/cmm/EgovDicGovTermExcelRegist";
                }
            }
        }

        status.setComplete();

        model.addAttribute("resultMsg", " Excel ? ?  ");

        return "forward:/cms/cmm/selectDicGovTermList.do";

    } catch (Exception ex) {

        model.addAttribute("resultMsg",
                " Excel ? ? ,  Excel ? ? ?. ");

        return "/cms/cmm/EgovDicGovTermExcelRegist";
    }
}

From source file:egovframework.oe1.cms.cmm.web.EgovOe1DicTermController.java

License:Apache License

/**
*   ? /*from   ww  w.  ja  v a  2 s  .c o  m*/
* @param ComDefaultVO - ?    VO
* @param model
* @return "forward:/cms/cmm/selectDicTermList.do"
* @exception Exception
*/
@RequestMapping("/cms/cmm/addDicTermExcelOK.do")
public String addDicTermExcelRegister(final HttpServletRequest request,
        @ModelAttribute("egovOe1DicTermVO") EgovOe1DicTermVO egovOe1DicTermVO, BindingResult bindingResult,
        Model model, SessionStatus status) throws Exception {

    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    if (bindingResult.hasErrors()) {
        model.addAttribute("egovOe1DicTermVO", egovOe1DicTermVO);
        return "/cms/cmm/addDicTermExcel";
    }

    model.addAttribute("searchMode", egovOe1DicTermVO);

    //
    EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    try {

        final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
        final Map<String, MultipartFile> files = multiRequest.getFileMap();

        Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator();
        MultipartFile file;

        String filePath = "";

        while (itr.hasNext()) {
            Entry<String, MultipartFile> entry = itr.next();

            file = entry.getValue();
            if (!"".equals(file.getOriginalFilename())) {

                String _storePath = propertyService.getString("Globals.fileStorePath");

                File saveFolder = new File(_storePath);
                if (!saveFolder.exists() || saveFolder.isFile()) {
                    saveFolder.mkdirs();
                }

                String orginFileName = file.getOriginalFilename();
                int _index = orginFileName.lastIndexOf(".");
                String fileName = orginFileName.substring(0, _index);
                String fileExt = orginFileName.substring(_index + 1);
                long _size = file.getSize();

                if (!"".equals(orginFileName)) {
                    filePath = _storePath + File.separator + "StandardTermStatus.xls";
                    file.transferTo(new File(filePath));
                }

                //                  System.out.println("?=====>"+orginFileName);
                //                  System.out.println("?=====>"+fileName);
                //                  System.out.println("?=====>"+fileExt);
                //                  System.out.println("??=====>"+_size);
                //                  System.out.println("??=====>"+filePath);

                if ((fileExt.equals("xls") || fileExt.equals("xlsx"))
                        && (filePath != null && !"".equals(filePath))) {

                    HSSFWorkbook wbT = excelService.loadWorkbook(filePath);
                    HSSFSheet sheetT = wbT.getSheet(wbT.getSheetName(0));

                    HSSFRow rowValue = sheetT.getRow(2);
                    HSSFCell cellValue0 = rowValue.getCell(0); //
                    HSSFCell cellValue1 = rowValue.getCell(1); //
                    HSSFCell cellValue2 = rowValue.getCell(2); //?(Full Name)
                    HSSFCell cellValue3 = rowValue.getCell(3); //?
                    HSSFCell cellValue4 = rowValue.getCell(4); //
                    HSSFCell cellValue6 = rowValue.getCell(6); //?
                    String synonm = (cellValue0 + "").trim();
                    String wordNm = (cellValue1 + "").trim();
                    String engNm = (cellValue2 + "").trim();
                    String wordNmEngAbrv = (cellValue3 + "").trim();
                    String wordDc = (cellValue4 + "").trim();
                    String useAt = (cellValue6 + "").trim();

                    //System.out.println("synonm====>"+synonm);
                    //System.out.println("wordNm====>"+wordNm);
                    //System.out.println("engNm====>"+engNm);
                    //System.out.println("wordNmEngAbrv====>"+wordNmEngAbrv);
                    //System.out.println("wordDc====>"+wordDc);
                    //System.out.println("useAt====>"+useAt);

                    if (!"".equals(synonm) || !"".equals(wordNm)
                            || !"?(Full Name)".equals(engNm) || !"?".equals(wordNmEngAbrv)
                            || !"".equals(wordDc) || !"?".equals(useAt)) {
                        model.addAttribute("resultMsg",
                                " EXCEL ?? .   .");
                        return "/cms/cmm/EgovDicTermExcelRegist";
                    }

                    List<EgovOe1DicTermVO> dicTermListVO = new ArrayList<EgovOe1DicTermVO>();

                    for (int i = 3; i <= sheetT.getLastRowNum(); i++) {

                        HSSFRow row1 = sheetT.getRow(i);

                        HSSFCell cell0 = row1.getCell(0); //(/??)
                        HSSFCell cell1 = row1.getCell(1); //
                        HSSFCell cell2 = row1.getCell(2); //?
                        HSSFCell cell3 = row1.getCell(3); //?
                        HSSFCell cell4 = row1.getCell(4); //
                        HSSFCell cell6 = row1.getCell(6); //

                        synonm = (cell0 + "").trim();
                        wordNm = (cell1 + "").trim();
                        engNm = (cell2 + "").trim();
                        wordNmEngAbrv = (cell3 + "").trim();
                        wordDc = (cell4 + "").trim();
                        useAt = (cell6 + "").trim();

                        //                        System.out.println("synonm=======>"+synonm);
                        //                        System.out.println("wordNm=======>"+wordNm);
                        //                        System.out.println("engNm=======>"+engNm);
                        //                        System.out.println("wordNmEngAbrv=======>"+wordNmEngAbrv);
                        //                        System.out.println("wordDc=======>"+wordDc);
                        //                        System.out.println("useAt=======>"+useAt);

                        if (("".equals(synonm) || "??".equals(synonm))
                                && (!"".equals(synonm) && synonm != null)
                                && (!"".equals(wordNm) && wordNm != null)
                                && (!"".equals(engNm) && engNm != null)
                                && (!"".equals(wordNmEngAbrv) && wordNmEngAbrv != null)) {
                            EgovOe1DicTermVO egovOe1DicTermExcelVO = new EgovOe1DicTermVO();
                            egovOe1DicTermExcelVO.setSynonm(synonm);
                            egovOe1DicTermExcelVO.setWordNm(wordNm);
                            egovOe1DicTermExcelVO.setEngNm(engNm);
                            egovOe1DicTermExcelVO.setWordNmEngAbrv(wordNmEngAbrv);
                            egovOe1DicTermExcelVO.setWordDc(wordDc);
                            if (useAt.equals("")) {
                                egovOe1DicTermExcelVO.setUseAt("Y");
                            } else {
                                egovOe1DicTermExcelVO.setUseAt("N");
                            }
                            egovOe1DicTermExcelVO.setFrstRegisterId(user.getMberId());

                            dicTermListVO.add(egovOe1DicTermExcelVO);

                            for (int kk = 0; kk < dicTermListVO.size(); kk++) {
                                if (kk > 1) {
                                    //                                   System.out.println("synonm=======>"+egovOe1DicTermExcelVO.getSynonm());
                                    //                                   System.out.println("wordNm=======>"+egovOe1DicTermExcelVO.getWordNm());
                                    //                                   System.out.println("engNm=======>"+egovOe1DicTermExcelVO.getEngNm());
                                    //                                   System.out.println("wordNmEngAbrv=======>"+egovOe1DicTermExcelVO.getWordNmEngAbrv());
                                    //                                   System.out.println("wordDc=======>"+egovOe1DicTermExcelVO.getWordDc());
                                    //                                   System.out.println("useAt=======>"+egovOe1DicTermExcelVO.getUseAt());
                                    //                                   System.out.println("dicTermListVO.get(kk-1).getWordNm().trim()====>"+dicTermListVO.get(kk-1).getWordNm().trim());
                                    //                                  System.out.println("kk=================="+kk);
                                    //                                   System.out.println("jj=================="+i);
                                    //                                   System.out.println("============================================");
                                    if (dicTermListVO.get(kk - 1).getWordNm().trim().equals(wordNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                    if (dicTermListVO.get(kk - 1).getEngNm().trim().equals(engNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?(Full Name)? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                    if (dicTermListVO.get(kk - 1).getWordNmEngAbrv().trim()
                                            .equals(wordNmEngAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                } else if (kk == 1) {
                                    //                                   System.out.println("synonm=======>"+egovOe1DicTermExcelVO.getSynonm());
                                    //                                   System.out.println("wordNm=======>"+egovOe1DicTermExcelVO.getWordNm());
                                    //                                   System.out.println("engNm=======>"+egovOe1DicTermExcelVO.getEngNm());
                                    //                                   System.out.println("wordNmEngAbrv=======>"+egovOe1DicTermExcelVO.getWordNmEngAbrv());
                                    //                                   System.out.println("wordDc=======>"+egovOe1DicTermExcelVO.getWordDc());
                                    //                                   System.out.println("useAt=======>"+egovOe1DicTermExcelVO.getUseAt());
                                    //                                   System.out.println("dicTermListVO.get(kk-1).getWordNm().trim()====>"+dicTermListVO.get(kk-1).getWordNm().trim());
                                    //                                  System.out.println("kk=================="+i);
                                    //                                   System.out.println("============================================");
                                    if (dicTermListVO.get(kk - 1).getWordNm().trim().equals(wordNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                    if (dicTermListVO.get(kk - 1).getEngNm().trim().equals(engNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?(Full Name)? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                    if (dicTermListVO.get(kk - 1).getWordNmEngAbrv().trim()
                                            .equals(wordNmEngAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?? . ?    .");
                                        return "/cms/cmm/EgovDicTermExcelRegist";
                                    }
                                }
                            }

                        } else {
                            if (!"".equals(synonm) && !"??".equals(synonm)) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "???  ? /??  . ?    .");
                            }
                            if ("".equals(synonm) || synonm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "???  ? . ?    .");
                            }
                            if ("".equals(wordNm) || wordNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            if ("".equals(engNm) || engNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ?(Full Name)? . ?    .");
                            }
                            if ("".equals(wordNmEngAbrv) || wordNmEngAbrv == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            if ("".equals(wordDc) || wordDc == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            return "/cms/cmm/EgovDicTermExcelRegist";
                        }
                    }

                    // ? ??    .
                    egovOe1DicTermService.deleteExcelDicTerm();

                    List<EgovOe1DicTermVO> list = dicTermListVO;

                    for (EgovOe1DicTermVO dicTermVO : list) {

                        if ("??".equals(dicTermVO.getSynonm())) {
                            egovOe1DicTermService.insertExcelDicTermSynonm(dicTermVO);
                        } else {
                            egovOe1DicTermService.insertExcelDicTerm(dicTermVO);
                        }
                    }

                } else {
                    model.addAttribute("resultMsg",
                            " EXCEL ?? .   .");
                    return "/cms/cmm/EgovDicTermExcelRegist";
                }
            }
        }

        status.setComplete();

        model.addAttribute("resultMsg", " Excel ? ?  ");

        return "forward:/cms/cmm/selectDicTermList.do";

    } catch (Exception ex) {

        model.addAttribute("resultMsg",
                " Excel ? ? ,  Excel ? ? ?. ");

        return "/cms/cmm/EgovDicTermExcelRegist";
    }
}

From source file:egovframework.oe1.cms.cmm.web.EgovOe1DicWordController.java

License:Apache License

/**
*   ? // ww  w. ja v a2  s . c o  m
* @param EgovOe1DicWordVO - ?    VO
* @param model
* @return "forward:/cms/cmm/selectDicWordList.do"
* @exception Exception
*/
@RequestMapping("/cms/cmm/addDicWordExcelOK.do")
public String addDicWordExcelRegister(final HttpServletRequest request,
        @ModelAttribute("egovOe1DicWordVO") EgovOe1DicWordVO egovOe1DicWordVO, BindingResult bindingResult,
        Model model, SessionStatus status) throws Exception {

    Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
    if (!isAuthenticated) {
        return "/cms/com/EgovLoginUsr"; //? ??
    }

    if (bindingResult.hasErrors()) {
        model.addAttribute("egovOe1DicWordVO", egovOe1DicWordVO);
        return "/cms/cmm/addDicWord";
    }

    model.addAttribute("searchMode", egovOe1DicWordVO);

    //
    EgovOe1LoginVO user = (EgovOe1LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

    try {

        final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
        final Map<String, MultipartFile> files = multiRequest.getFileMap();

        Iterator<Entry<String, MultipartFile>> itr = files.entrySet().iterator();
        MultipartFile file;

        String filePath = "";

        while (itr.hasNext()) {
            Entry<String, MultipartFile> entry = itr.next();

            file = entry.getValue();
            if (!"".equals(file.getOriginalFilename())) {

                String _storePath = propertyService.getString("Globals.fileStorePath");

                File saveFolder = new File(_storePath);
                if (!saveFolder.exists() || saveFolder.isFile()) {
                    saveFolder.mkdirs();
                }

                String orginFileName = file.getOriginalFilename();
                int _index = orginFileName.lastIndexOf(".");
                String fileName = orginFileName.substring(0, _index);
                String fileExt = orginFileName.substring(_index + 1);
                long _size = file.getSize();

                if (!"".equals(orginFileName)) {
                    filePath = _storePath + File.separator + "StandardWordStatus.xls";
                    file.transferTo(new File(filePath));
                }

                //System.out.println("?=====>"+orginFileName);
                //System.out.println("?=====>"+fileName);
                //System.out.println("?=====>"+fileExt);
                //System.out.println("??=====>"+_size);
                //System.out.println("??=====>"+filePath);

                if ((fileExt.equals("xls") || fileExt.equals("xlsx"))
                        && (filePath != null && !"".equals(filePath))) {

                    HSSFWorkbook wbT = excelService.loadWorkbook(filePath);
                    HSSFSheet sheetT = wbT.getSheet(wbT.getSheetName(0));

                    HSSFRow rowValue = sheetT.getRow(2);
                    HSSFCell cellValue0 = rowValue.getCell(0); //
                    HSSFCell cellValue1 = rowValue.getCell(1); //?(Full Name)
                    HSSFCell cellValue2 = rowValue.getCell(2); //?
                    HSSFCell cellValue3 = rowValue.getCell(3); //
                    HSSFCell cellValue5 = rowValue.getCell(5); //?
                    String wordNm = (cellValue0 + "").trim();
                    String engNm = (cellValue1 + "").trim();
                    String wordNmEngAbrv = (cellValue2 + "").trim();
                    String wordDc = (cellValue3 + "").trim();
                    String useAt = (cellValue5 + "").trim();

                    //System.out.println("wordNm====>"+wordNm);
                    //System.out.println("engNm====>"+engNm);
                    //System.out.println("wordNmEngAbrv====>"+wordNmEngAbrv);
                    //System.out.println("wordDc====>"+wordDc);
                    //System.out.println("useAt====>"+useAt);

                    if (!"".equals(wordNm) || !"?(Full Name)".equals(engNm)
                            || !"?".equals(wordNmEngAbrv) || !"".equals(wordDc)
                            || !"?".equals(useAt)) {
                        model.addAttribute("resultMsg",
                                " EXCEL ?? .   .");
                        return "/cms/cmm/EgovDicWordExcelRegist";
                    }

                    List<EgovOe1DicWordVO> dicWordListVO = new ArrayList<EgovOe1DicWordVO>();

                    for (int i = 3; i <= sheetT.getLastRowNum(); i++) {
                        HSSFRow row1 = sheetT.getRow(i);
                        HSSFCell cell0 = row1.getCell(0); //
                        HSSFCell cell1 = row1.getCell(1); //?
                        HSSFCell cell2 = row1.getCell(2); //?
                        HSSFCell cell3 = row1.getCell(3); //
                        HSSFCell cell5 = row1.getCell(5); //

                        wordNm = (cell0 + "").trim();
                        engNm = (cell1 + "").trim();
                        wordNmEngAbrv = (cell2 + "").trim();
                        wordDc = (cell3 + "").trim();
                        useAt = (cell5 + "").trim();

                        if ((!"".equals(wordNm) && wordNm != null) && (!"".equals(engNm) && engNm != null)
                                && (!"".equals(wordNmEngAbrv) && wordNmEngAbrv != null)
                                && (!"".equals(wordDc) && wordDc != null)) {
                            EgovOe1DicWordVO egovOe1DicWordExcelVO = new EgovOe1DicWordVO();
                            egovOe1DicWordExcelVO.setWrdNm(wordNm);
                            egovOe1DicWordExcelVO.setWrdEngNm(engNm);
                            egovOe1DicWordExcelVO.setWrdEngAbrv(wordNmEngAbrv);
                            egovOe1DicWordExcelVO.setWrdDc(wordDc);
                            if (useAt.equals("")) {
                                egovOe1DicWordExcelVO.setUseAt("Y");
                            } else {
                                egovOe1DicWordExcelVO.setUseAt("N");
                            }
                            egovOe1DicWordExcelVO.setFrstRegisterId(user.getMberId());

                            dicWordListVO.add(egovOe1DicWordExcelVO);

                            for (int kk = 0; kk < dicWordListVO.size(); kk++) {
                                if (kk > 1) {
                                    if (dicWordListVO.get(kk - 1).getWrdNm().trim().equals(wordNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                    if (dicWordListVO.get(kk - 1).getWrdEngNm().trim().equals(engNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?(Full Name)? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                    if (dicWordListVO.get(kk - 1).getWrdEngAbrv().trim()
                                            .equals(wordNmEngAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                } else if (kk == 1) {
                                    if (dicWordListVO.get(kk - 1).getWrdNm().trim().equals(wordNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                    if (dicWordListVO.get(kk - 1).getWrdEngNm().trim().equals(engNm)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?(Full Name)? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                    if (dicWordListVO.get(kk - 1).getWrdEngAbrv().trim()
                                            .equals(wordNmEngAbrv)) {
                                        model.addAttribute("resultMsg", (i + 1)
                                                + "??? ?? . ?    .");
                                        return "/cms/cmm/EgovDicWordExcelRegist";
                                    }
                                }
                            }

                        } else {
                            if ("".equals(wordNm) || wordNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            if ("".equals(engNm) || engNm == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ?(Full Name)? . ?    .");
                            }
                            if ("".equals(wordNmEngAbrv) || wordNmEngAbrv == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ?? . ?    .");
                            }
                            if ("".equals(wordDc) || wordDc == null) {
                                model.addAttribute("resultMsg", (i + 1)
                                        + "??? ? . ?    .");
                            }
                            return "/cms/cmm/EgovDicWordExcelRegist";
                        }
                    }

                    // ? ??    .
                    egovOe1DicWordService.deleteExcelDicWord();

                    List<EgovOe1DicWordVO> list = dicWordListVO;
                    for (EgovOe1DicWordVO dicWordVo : list) {
                        egovOe1DicWordService.insertExcelDicWord(dicWordVo);
                    }

                } else {
                    model.addAttribute("resultMsg",
                            " EXCEL ?? .   .");
                    return "/cms/cmm/EgovDicWordExcelRegist";
                }
            }
        }

        status.setComplete();

        model.addAttribute("resultMsg", " Excel ? ?  ");

        return "forward:/cms/cmm/selectDicWordList.do";

    } catch (Exception ex) {

        model.addAttribute("resultMsg",
                " Excel ? ? ,  Excel ? ? ?. ");

        return "/cms/cmm/EgovDicWordExcelRegist";
    }
}

From source file:eu.cassandra.training.entities.Installation.java

License:Apache License

/**
 * This is the parser for the measurement file. It parses through the file and
 * creates the arrays of the active and reactive power consumptions.
 *//*from www.j av a 2s  . com*/
public void parseMeasurementsFile() throws IOException {

    ArrayList<Double> temp = new ArrayList<Double>();
    ArrayList<Double> temp2 = new ArrayList<Double>();

    String extension = measurementsFile.substring(measurementsFile.length() - 3, measurementsFile.length());

    switch (extension) {

    case "csv":

        boolean startFlag = true;

        File file = new File(measurementsFile);
        Scanner scanner = new Scanner(file);

        int counter = 0;

        while (scanner.hasNext()) {

            String line = scanner.nextLine();
            // System.out.println(line);

            if (startFlag) {
                if (line.split(",")[0].equalsIgnoreCase("1")) {

                    startDate = new DateTime(2012, 01, 01, 00, 00);

                } else {

                    int year = Integer.parseInt(line.split(",")[0].substring(0, 4));
                    int month = Integer.parseInt(line.split(",")[0].substring(4, 6));
                    int day = Integer.parseInt(line.split(",")[0].substring(6, 8));
                    int hour = 0;
                    int minute = 0;

                    startDate = new DateTime(year, month, day, hour, minute);

                }

                // System.out.println(startDate.toString());
                startFlag = false;
            }

            temp.add(Double.parseDouble(line.split(",")[1]));

            if (!activeOnly)
                temp2.add(Double.parseDouble(line.split(",")[2]));

            counter++;
        }

        endDate = startDate.plusMinutes(counter);

        // System.out.println(endDate.toString());

        scanner.close();
        break;

    case "xls":

        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(measurementsFile));

        // Get the first sheet.
        HSSFSheet sheet = workbook.getSheetAt(0);
        for (int i = 0; i < sheet.getLastRowNum(); i++) {

            // Set value of the first cell.
            HSSFRow row = sheet.getRow(i + 1);
            temp.add(row.getCell(1).getNumericCellValue());
            if (!activeOnly)
                temp2.add(row.getCell(2).getNumericCellValue());
        }

        break;

    }

    activePower = new double[temp.size()];

    for (int i = 0; i < temp.size(); i++)
        activePower[i] = temp.get(i);

    if (!activeOnly) {
        reactivePower = new double[temp2.size()];
        for (int i = 0; i < temp2.size(); i++)
            reactivePower[i] = temp2.get(i);
    }

}

From source file:eu.cassandra.training.utils.Utils.java

License:Apache License

/**
 * This is the parser for the measurement file. It parses through the file and
 * checks for errors. It can parse through .csv and .xls file and uses
 * different libraries for each file type.
 * //from  w  ww . j  a v  a 2s  .c om
 * @param measurementsFile
 *          The file name of the measurements file.
 * @param power
 *          The type of data sets contained within the file (only active or
 *          active and reactive power)
 * @return the line of error or -1 if no error is found.
 * @throws IOException
 */
public static int parseMeasurementsFile(String measurementsFile, boolean power) throws IOException {

    int result = -1;

    String extension = measurementsFile.substring(measurementsFile.length() - 3, measurementsFile.length());

    switch (extension) {

    case "csv":

        File file = new File(measurementsFile);
        Scanner scanner = new Scanner(file);
        scanner.nextLine();
        int counter = 2;
        while (scanner.hasNext()) {

            String line = scanner.nextLine();

            String[] testString = line.split(",");

            if (power) {
                if (testString.length != 2)
                    result = counter;
                try {
                    Double.parseDouble(testString[1]);
                } catch (NumberFormatException e) {
                    result = counter;
                }
            } else {
                if (testString.length != 3)
                    result = counter;
                try {
                    Double.parseDouble(testString[1]);
                    Double.parseDouble(testString[2]);
                } catch (NumberFormatException e) {
                    result = counter;
                }

                if (result != -1)
                    break;
            }
            counter++;
        }

        scanner.close();
        System.out.println("Your csv file has been read!");
        break;

    case "xls":

        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(measurementsFile));

        // Get the first sheet.
        HSSFSheet sheet = workbook.getSheetAt(0);
        for (int i = 0; i < sheet.getLastRowNum(); i++) {
            // Set value of the first cell.
            HSSFRow row = sheet.getRow(i + 1);

            if (power) {
                if (row.getCell(2) != null)
                    result = i + 2;
                try {
                    Double.parseDouble(row.getCell(1).toString());
                } catch (NumberFormatException e) {
                    result = i + 2;
                }
            } else {
                if (row.getCell(3) != null)
                    result = i + 2;
                try {
                    Double.parseDouble(row.getCell(1).toString());
                    Double.parseDouble(row.getCell(2).toString());
                } catch (NumberFormatException e) {
                    result = i + 2;
                }
            }

            if (result != -1)
                break;
        }

        System.out.println("Your excel file has been read!");
        break;

    }

    return result;

}

From source file:excel.FileExcel.java

public void get_daily_data(String pathfile) {
    File excelfile = new File(pathfile);
    updStockData = new ArrayList<>();
    if (excelfile.exists()) {
        try {/*from   ww w  .j a v  a  2 s  . c om*/
            FileInputStream fis = new FileInputStream(excelfile);
            HSSFWorkbook workbook = new HSSFWorkbook(fis);
            HSSFSheet sheet = workbook.getSheetAt(0);
            int flagfound;
            for (int i = 10; i < (sheet.getLastRowNum() - 1); i++) {
                if (!sheet.getRow(i).getCell(13).getStringCellValue().isEmpty()) {
                    if (Integer.valueOf(
                            (int) Math.round(sheet.getRow(i).getCell(18).getNumericCellValue())) != 0) { // if price 0
                        flagfound = 0;
                        for (int j = 0; j < updStockData.size(); j++) { // in case there are many incoming data for same item
                            if (updStockData.get(j).kode_barang
                                    .equals(sheet.getRow(i).getCell(13).getStringCellValue())) {
                                updStockData.get(j).jumlah_barang += Integer.valueOf(
                                        (int) Math.round(sheet.getRow(i).getCell(19).getNumericCellValue()));
                                flagfound = 1;
                                break;
                            }
                        }
                        if (flagfound == 0) { // if already found, doesn't need to create new entry
                            StockData constructor = new StockData();
                            constructor.kode_barang = sheet.getRow(i).getCell(13).getStringCellValue();
                            constructor.jumlah_barang = Integer.valueOf(
                                    (int) Math.round(sheet.getRow(i).getCell(19).getNumericCellValue()));
                            updStockData.add(constructor);
                        }
                    }
                }
            }
        } catch (Exception e) {
            System.out.println("error : " + e);
        }
    } else {
        System.out.println("error file doesn't exist");
    }
}

From source file:fft.FFT.java

License:Open Source License

public static void main(String[] args) throws IOException {

    InputStream myxls = new FileInputStream("/Users/huangge/Documents/workspace/fft/src/BxDec99.xls");
    HSSFWorkbook wb = new HSSFWorkbook(myxls);
    HSSFSheet sheet = wb.getSheetAt(0);
    int rowStart = Math.min(15, sheet.getFirstRowNum());
    int rowEnd = Math.max(1400, sheet.getLastRowNum());
    Row r_for_rowCount = sheet.getRow(0);
    int lastColumn = Math.min(r_for_rowCount.getLastCellNum(), 1000);

    double[][] res = new double[lastColumn - 1][rowEnd];
    Workbook wb_out = new HSSFWorkbook(); // or new XSSFWorkbook();
    Sheet sheet_out = wb_out.createSheet();
    int count = 0;
    for (int j = 1; j < lastColumn; j++) {//make res matrix
        count = 0;//ww  w .j  ava2  s.  c  om
        for (int i = 1; i <= rowEnd; i++) {
            Row r = sheet.getRow(i);
            Cell c = r.getCell(3, Row.RETURN_BLANK_AS_NULL);
            if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
                break;
            } else if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                res[j - 1][i - 1] = c.getNumericCellValue();
                count++;
            }
        }
    }

    int N = count;
    int nextPowTwo = 1;
    while (nextPowTwo < N) {
        nextPowTwo += nextPowTwo;
    }
    N = nextPowTwo;
    FFT fft = new FFT(N);
    double[] window = fft.getWindow();
    double[] re = new double[N];
    Arrays.fill(re, 0);
    ;
    double[] im = new double[N];

    for (int i = 0; i < re.length / 2; i++) {//initial sheet
        Row row_cre = sheet_out.createRow(i);
        for (int k = 0; k < lastColumn - 1; k++) {
            Cell cell = row_cre.createCell((short) (k));
        }
    }

    for (int j = 1; j < lastColumn; j++) {//make result sheet
        for (int i = 0; i < count; i++) {
            re[i] = res[j - 1][i];
            im[i] = 0;
        }
        beforeAfter(fft, re, im);
        for (int i = 0; i < re.length / 2; i++) {
            Row row_out = sheet_out.getRow(i);
            Cell cell = row_out.getCell((short) (j - 1));
            cell.setCellValue(Math.abs(re[i]));
        }

    }

    FileOutputStream fileOut//write file
            = new FileOutputStream("/Users/huangge/Documents/workspace/fft/src/workbook.xls");
    wb_out.write(fileOut);
    fileOut.close();

    long time = System.currentTimeMillis();
    double iter = 10;
    for (int i = 0; i < iter; i++)
        // fft.fft(re,im);
        time = System.currentTimeMillis() - time;
    System.out.println("Averaged " + (time / iter) + "ms per iteration");
}

From source file:FormatConvert.exceloperation.Excel2csv.java

public static void copySheets2CSV(HSSFSheet sheet, String csvfile) {
    int maxColumnNum = 0;

    try {// w w  w .j  a v  a  2s  . c o  m
        FileWriter fw = new FileWriter(csvfile);

        String str = "";
        for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
            HSSFRow srcRow = sheet.getRow(i);

            if (srcRow != null) {
                for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
                    if (j != srcRow.getLastCellNum()) {
                        str = str + srcRow.getCell(j).getStringCellValue() + ",";
                    } else {
                        str = str + srcRow.getCell(j).getStringCellValue() + "\r\n";
                    }

                }
                fw.append(str);
            }
            str = "";
        }

        fw.flush();
        fw.close();
    } catch (IOException ex) {

    }
    //Util.copyPictures(newSheet,sheet) ;
}

From source file:fr.amapj.view.views.importdonnees.tools.AbstractImporter.java

License:Open Source License

private void processFile() throws IOException {

    // Get the workbook instance for XLS file
    HSSFWorkbook workbook = new HSSFWorkbook(new ByteArrayInputStream(baos.toByteArray()));
    DataFormatter df = new DataFormatter(Locale.FRANCE);

    // Get first sheet from the workbook
    HSSFSheet sheet = workbook.getSheetAt(0);

    int numCol = getNumCol();

    List<T> existing = getAllDataInDatabase();

    List<T> utilisateurs = new ArrayList<>();

    int lastRowNum = sheet.getLastRowNum();

    for (int numLigne = 2; numLigne <= lastRowNum + 1; numLigne++) {
        Row row = sheet.getRow(numLigne - 1);

        String[] strs = new String[numCol];
        boolean isEmptyLine = true;
        for (int i = 0; i < strs.length; i++) {
            strs[i] = getCell(row, i, df);
            if ((strs[i] != null) && (strs[i].length() > 0)) {
                isEmptyLine = false;//  ww w .j a  v a2  s .co m
            }
        }

        if (isEmptyLine == false) {

            // On cre le DTO
            T dto = createDto(strs);

            // On vrifie tout d'abord si les elements de base sont bien prsents
            performBasicCheck(dto, numLigne);
            if (errorMessage.size() != 0) {
                return;
            }

            // On verifie ensuite si l'lment est bien compatible avec les autres lignes du fichier 
            checkLineInSameFile(utilisateurs, dto, numLigne);
            if (errorMessage.size() != 0) {
                return;
            }

            // On verifie ensuite si l'lment est bien compatible avec les autres enregistrement de la base         
            checkLineInDataBase(existing, dto, numLigne);
            if (errorMessage.size() != 0) {
                return;
            }

            utilisateurs.add(dto);
        }

    }

    saveInDataBase(utilisateurs);
}

From source file:framework.retrieval.engine.index.create.impl.file.parse.ExcelFileContentParser.java

License:Apache License

public String getContent(RFileDocument document, String charsetName) {

    InputStream fileInputStream = null;
    StringBuffer content = new StringBuffer();

    try {/*from  ww  w .  j a va 2 s .  co m*/
        fileInputStream = new FileInputStream(document.getFile());
        HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);// Excel

        if (workbook != null) {
            int numSheetsNumber = workbook.getNumberOfSheets();
            for (int numSheets = 0; numSheets < numSheetsNumber; numSheets++) {
                HSSFSheet aSheet = workbook.getSheetAt(numSheets);// sheet
                if (aSheet != null) {
                    int lastRowNum = aSheet.getLastRowNum();
                    for (int rowNumOfSheet = 0; rowNumOfSheet <= lastRowNum; rowNumOfSheet++) {
                        HSSFRow aRow = aSheet.getRow(rowNumOfSheet); // 
                        if (aRow != null) {
                            int lastCellNum = aRow.getLastCellNum();
                            for (int cellNumOfRow = 0; cellNumOfRow <= lastCellNum; cellNumOfRow++) {
                                HSSFCell aCell = aRow.getCell(cellNumOfRow);// 
                                if (aCell != null) {
                                    int cellType = aCell.getCellType();
                                    if (cellType == HSSFCell.CELL_TYPE_STRING) {
                                        String value = StringClass.getString(aCell.getStringCellValue());
                                        content.append(value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        RetrievalUtil.errorLog(log, document.getFile().getAbsolutePath(), e);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (Exception e) {

            }
        }
    }

    return content.toString();

}