Example usage for org.apache.poi.ss.usermodel Row cellIterator

List of usage examples for org.apache.poi.ss.usermodel Row cellIterator

Introduction

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

Prototype

Iterator<Cell> cellIterator();

Source Link

Usage

From source file:ADP_Streamline.MatrixReader.java

public String check() throws Exception {

    List<String> ClientRoles = new ArrayList<>();
    List<String> PartnerRoles = new ArrayList<>();
    List<String> ADPRoles = new ArrayList<>();
    List<String> Rights = new ArrayList<>();

    String rightscolumn = "";
    String rights = "";
    String roles = "";
    String cellwithx;//from   www  . j av a  2s  . co m

    int righstrow = 0;
    int columncount;
    int rowcount;
    int roleslenght;
    int rightslenght = 0;

    Boolean client = false;
    Boolean partner = false;
    Boolean adp;
    Boolean rightstart = false;

    Iterator<Row> rowIterator;
    Iterator<Cell> cellIterator;

    Row row;
    Cell cell;

    OracleJDBC oracle = new OracleJDBC();

    try {

        FileInputStream file = new FileInputStream(
                new File("C:\\Users\\frodri1\\Documents\\SPM 1.2_RoleMatrix_Demo.xlsx"));

        //Create Workbook instance holding reference to .xlsx file
        XSSFWorkbook workbook = new XSSFWorkbook(file);

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

        //Iterate through each rows one by one
        rowIterator = sheet.iterator();

        rowcount = 2;
        columncount = 0;

        while (rowIterator.hasNext()) {

            row = rowIterator.next();
            //if(adp) {break;}
            adp = false;

            //For each row, iterate through all the columns
            cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {

                cell = cellIterator.next();

                if (cell.getStringCellValue().contentEquals("Right")) {
                    rightscolumn = CellReference.convertNumToColString(cell.getColumnIndex());
                    righstrow = cell.getRowIndex();
                    rightstart = true;
                }

                if (cell.getStringCellValue().contentEquals("Client")) {
                    client = true;
                }

                if (cell.getStringCellValue().contentEquals("Partner")) {
                    partner = true;
                    client = false;
                }

                if (cell.getStringCellValue().contentEquals("ADP")) {
                    partner = false;
                    client = false;
                    adp = true;
                }

                if (client) {
                    ClientRoles.add(
                            CellIteration(sheet, CellReference.convertNumToColString(cell.getColumnIndex()),
                                    righstrow, columncount, 0).trim());
                }

                if (partner) {
                    PartnerRoles.add(
                            CellIteration(sheet, CellReference.convertNumToColString(cell.getColumnIndex()),
                                    righstrow, columncount, 0).trim());
                }

                if (adp) {
                    ADPRoles.add(
                            CellIteration(sheet, CellReference.convertNumToColString(cell.getColumnIndex()),
                                    righstrow, columncount, 0).trim());
                }
            }

            if (rightstart) {

                rights = CellIteration(sheet, rightscolumn, righstrow, columncount, rowcount);

                if (!"".equals(rights)) {

                    Rights.add(rights.trim());
                    rightslenght++;
                    rowcount++;
                } else
                    break;
            }
        }

        roleslenght = ClientRoles.size() + PartnerRoles.size() + ADPRoles.size();

        for (int i = 0; i < rightslenght; i++) {

            for (int l = 0; l < roleslenght; l++) {

                cellwithx = CellIteration(sheet, rightscolumn, righstrow, l + 1, i + 2);
                if ("x".equals(cellwithx)) {

                    if (l < ClientRoles.size()) {

                        rights = Rights.get(i);
                        roles = ClientRoles.get(l);

                        oracle.check(rights, roles);
                    }

                    if (l >= ClientRoles.size() && l < (ClientRoles.size() + PartnerRoles.size())) {

                        rights = Rights.get(i);
                        roles = PartnerRoles.get(l - ClientRoles.size());

                    }

                    if (l >= ClientRoles.size() + PartnerRoles.size()) {

                        rights = Rights.get(i);
                        roles = ADPRoles.get(l - (ClientRoles.size() + PartnerRoles.size()));

                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}

From source file:Algorithm.Method1.java

public String[] MethodTest(String Path) {
    StringBuffer keyword1 = new StringBuffer();
    try {// w w  w. j a  v a2 s.c o  m
        Hashtable hash = new Hashtable();

        FileInputStream file = new FileInputStream(new File(Path));
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet1 = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet1.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            //Row rowNew =sheetNew.createRow(rowNumNew++);
            //For each row, iterate through all the columns
            Iterator<org.apache.poi.ss.usermodel.Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                org.apache.poi.ss.usermodel.Cell cell = cellIterator.next();
                // Cell cellNew =rowNew.createCell(cellNumNew++);
                //Check the cell type and format accordingly
                switch (cell.getCellType()) {
                case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
                    break;
                case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
                    String result = cell.getStringCellValue();
                    if (hash.containsKey(result)) {
                        int f = Integer.parseInt(hash.get(result).toString());
                        f++;
                        hash.put(result, f);
                    } else {
                        hash.put(result, 1);
                    }

                }
            }

            //System.out.println("");
        }

        XSSFWorkbook workbookNew = new XSSFWorkbook();
        XSSFSheet sheetNew = workbookNew.createSheet("test");
        int rowNum = 0;

        Set s = hash.keySet();
        String key = new String();
        int t = 0;
        for (Iterator<String> i = s.iterator(); i.hasNext();) {
            key = i.next();
            Row rowNew = sheetNew.createRow(rowNum);
            org.apache.poi.ss.usermodel.Cell cellNew = rowNew.createCell(0);
            cellNew.setCellValue(key);
            keyword1.append(key + " ");
            org.apache.poi.ss.usermodel.Cell cellNew2 = rowNew.createCell(1);
            cellNew2.setCellValue(hash.get(key).toString());
            rowNum++;
            //sheet2.addCell(new Label(0,t , key));
            //System.out.println(hash.get(key));
            //sheet2.addCell(new Label(1,t , hash.get(key).toString()));
            t++;
        }

        FileOutputStream fileOut = new FileOutputStream(new File(Path.replace("???.xlsx", "method1.xlsx")));//new file
        workbookNew.write(fileOut);
        fileOut.close();

        file.close();

        // Workbook book = Workbook.getWorkbook(new File("n.xls"));

        //WritableWorkbook book2 = Workbook.createWorkbook(new File("method1.xls"));
        //
        // WritableSheet sheet2 = book2.createSheet("num1", 0);

        // 
        //Sheet sheet = book.getSheet(0);         
        //int rownum = sheet.getRows();// 
        /**
        Cell cell;
        for(int i = 0;i<rownum;i++){
           cell = sheet.getCell(0,i);
           String result = cell.getContents();
           if(hash.containsKey(result)){
          int f = Integer.parseInt(hash.get(result).toString());
          f++;
          hash.put(result, f);
           }else{
          hash.put(result, 1);
           }
        }
        */
        //??
        /*
        Set s=hash.keySet();
        String key = new String();
        int t = 0;
        for(Iterator<String> i=s.iterator();i.hasNext();){
           key = i.next();
           sheet2.addCell(new Label(0,t , key));
        //System.out.println(hash.get(key));
        sheet2.addCell(new Label(1,t , hash.get(key).toString()));
        t++;
        }
                
        book2.write();
        book2.close();
        */
        // book.close();
        System.out.print("method1");
    } catch (Exception e) {
        System.out.println(e);
    }
    return keyword1.toString().split(" ");
}

From source file:Algorithm.Method1.java

public String[] method1Out(String filepath) throws Exception {

    File fileout = new File("pp.txt");
    PrintWriter out1 = new PrintWriter(fileout);

    String[] out = null;//from  w ww  .  java2  s. c om
    ArrayList outList = new ArrayList<String>();
    String result;
    Hashtable hash = new Hashtable();
    FileInputStream file = new FileInputStream(new File(filepath));
    XSSFWorkbook workbook = new XSSFWorkbook(file);
    XSSFSheet sheet1 = workbook.getSheetAt(0);
    Iterator<Row> rowIterator = sheet1.iterator();
    //???excel?????
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();

        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            result = cell.getStringCellValue().trim();
            if (hash.containsKey(result)) {
                int f = Integer.parseInt(hash.get(result).toString());
                f++;
                hash.put(result, f);

            } else {
                hash.put(result, 1);

            }
        } //end while
    } //end while

    //???tf-idf
    Hashtable hash_2 = new Hashtable();
    File filein = new File("tfidf.txt");
    Scanner input = new Scanner(filein);
    String s;
    double d;

    while (input.hasNext()) {

        s = input.next().trim();
        d = input.nextDouble();

        hash_2.put(s, d);
    }

    //??
    Set ss = hash.keySet();
    String key = new String();
    //tf-idf
    for (Iterator<String> i = ss.iterator(); i.hasNext();) {
        key = i.next().trim();

        if (hash_2.containsKey(key)) {
            int tf = Integer.parseInt(hash.get(key).toString());
            double idf = Double.parseDouble(hash_2.get(key).toString());
            hash.put(key, tf * idf);
            //out1.println(key+" "+tf*idf);
        } else {
            hash.put(key, 0.1);
            //out1.println(key+" "+0.1);
        }

    }

    key = null;

    //tf-idf?
    Set ss2 = hash.keySet();

    String tmp = "";

    int size = hash.size();
    for (int j = 0; j < size; j++) {
        ss2 = hash.keySet();
        double max = 0;
        for (Iterator<String> i = ss2.iterator(); i.hasNext();) {
            key = i.next().trim();
            double xxoo = Double.parseDouble(hash.get(key).toString());
            if (xxoo > max) {
                //??
                max = xxoo;
                tmp = key;

            }

        }

        hash.remove(tmp);

        ss = hash.keySet();

        if (!outList.contains(tmp))
            outList.add(tmp);

    }

    //arraylist?
    out = (String[]) outList.toArray(new String[1]);

    //out1.close();
    /*
    for(int i=0;i<out.length;i++)
    {
    System.out.print(out[i]);
    }
        */
    return out;
}

From source file:Algorithm.Method2.java

public String[] MethodTest(String Path) {
    StringBuffer keyword1 = new StringBuffer();
    try {/*from   ww w.j  a v  a2 s . c om*/
        /**
        * ??excel
        * src
        * map?
        * result
        */

        String srcFilePath = Path;
        String mapFilePath = "??.xlsx";
        String newFilePath = Path.replace("???.xlsx", "method2.xlsx");

        FileInputStream srcFile = new FileInputStream(new File(srcFilePath));
        FileInputStream mapFile = new FileInputStream(new File(mapFilePath));

        XSSFWorkbook srcWorkbook = new XSSFWorkbook(srcFile);
        XSSFWorkbook mapWorkbook = new XSSFWorkbook(mapFile);
        XSSFWorkbook newWorkbook = new XSSFWorkbook();

        XSSFSheet srcSheet = srcWorkbook.getSheetAt(0);
        XSSFSheet mapSheet = mapWorkbook.getSheetAt(0);
        XSSFSheet newSheet = newWorkbook.createSheet("test");

        Iterator<Row> srcRowIterator = srcSheet.iterator();
        Iterator<Row> mapRowIterator = mapSheet.iterator();

        //map.xlst???mapList
        ArrayList mapList = new ArrayList();
        while (mapRowIterator.hasNext()) {
            Row row = mapRowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                String test = cell.getStringCellValue();
                mapList.add(test);
            }
        }

        //???mapArray,?
        int mapListLength = mapList.size();
        String[] mapArray = (String[]) mapList.toArray(new String[mapListLength]);

        //??mapResult,mapArray?src
        //,mapArray[i]src,mapResult[i]1?0
        int[] mapResult = new int[mapListLength];
        for (int i = 0; i < mapListLength; i++) {
            mapResult[i] = 0;
        }

        //?src.xlsx,?mapArray
        while (srcRowIterator.hasNext()) {
            Row row = srcRowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                String test = cell.getStringCellValue().trim();

                for (int i = 0; i < mapListLength; i++) {
                    if (test.equals(mapArray[i]))
                        mapResult[i] = 1;
                }
            }
        }

        //?mapResult,mapArrayresult
        int newRowNum = 0;
        for (int i = mapListLength - 1; i >= 0; i--) {
            if (mapResult[i] == 1) {
                Row newRow = newSheet.createRow(newRowNum++);
                Cell newCell = newRow.createCell(0);
                String test = mapArray[i];
                keyword1.append(test + " ");
                newCell.setCellValue(test);
            }
        }

        srcFile.close();
        mapFile.close();

        //FileOutputStream fileOut = new FileOutputStream(new File(newFilePath));
        // newWorkbook.write(fileOut);
        // fileOut.close();
        // System.out.print("method2");
    } catch (Exception e) {
        System.out.println(e);
    }

    return keyword1.toString().split(" ");
}

From source file:Algorithm.SegmentationAndNounFilter.java

public String[] SegmentationNounFilter(String filepath, String filename) {
    try {/*from   www  . java 2 s . c  o  m*/

        String mingciPath = filepath.replace(filename, "???.xlsx");
        ICTCLAS50 testICTCLAS50 = new ICTCLAS50();
        String argu = ".";
        if (testICTCLAS50.ICTCLAS_Init(argu.getBytes("GB2312")) == false) {
            System.out.println("Init Fail");
        } else {
            System.out.println("Init Succeed!");
        }

        StringBuffer input = new StringBuffer();
        FileInputStream file = new FileInputStream(new File(filepath));
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        XSSFSheet sheet1 = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet1.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            //Row rowNew =sheetNew.createRow(rowNumNew++);
            //For each row, iterate through all the columns
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                // Cell cellNew =rowNew.createCell(cellNumNew++);
                //Check the cell type and format accordingly
                switch (cell.getCellType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    break;
                case Cell.CELL_TYPE_STRING:
                    input.append(cell.getStringCellValue());

                }
            }

            //System.out.println("");
        }
        //?
        byte nativeBytes[] = testICTCLAS50.ICTCLAS_ParagraphProcess(input.toString().getBytes("GB2312"), 0, 1);

        String nativeStr = new String(nativeBytes, 0, nativeBytes.length, "GB2312");

        //xlsx
        XSSFWorkbook workbookNew = new XSSFWorkbook();
        XSSFSheet sheetNew = workbookNew.createSheet("test");
        int rowNum = 0;

        // WritableWorkbook book = Workbook.createWorkbook(new File("n.xls"));
        // WritableSheet sheet = book.createSheet("num1", 0);
        Scanner in = new Scanner(nativeStr);
        int i = 0;//
        while (in.hasNext()) {
            String ss = in.next();

            Pattern pattern = Pattern.compile("(.+?)/n.*");
            Matcher matcher = pattern.matcher(ss);
            if (matcher.find() && matcher.group(1).length() > 1 && !isDigit(matcher.group(1))) {

                //label = new jxl.write.Label(0, i, matcher.group(1));//?
                //sheet.addCell(label);
                Row rowNew = sheetNew.createRow(rowNum++);
                Cell cellNew = rowNew.createCell(0);
                cellNew.setCellValue(matcher.group(1));
                //i++;

            }
        }

        //    book.write();
        //   book.close();
        FileOutputStream fileOut = new FileOutputStream(new File(mingciPath));//new file
        workbookNew.write(fileOut);
        fileOut.close();

        //??            

        file.close();

        testICTCLAS50.ICTCLAS_Exit();

    } catch (Exception ex) {

    }

    return null;

}

From source file:ambit2.core.io.IteratingXLSReader.java

License:Open Source License

protected void processHeader(Row row) {

    Iterator cols = row.cellIterator();
    TreeMap columns = new TreeMap();
    while (cols.hasNext()) {
        Cell cell = (Cell) cols.next();// ww w  .  j a v  a 2s. co  m
        String value = cell.getStringCellValue();

        if (value.equals(defaultSMILESHeader))
            smilesIndex = cell.getColumnIndex();
        columns.put(new Integer(cell.getColumnIndex()), value);
    }
    Iterator i = columns.keySet().iterator();
    while (i.hasNext()) {
        Integer key = (Integer) i.next();
        setHeaderColumn(key.intValue(), columns.get(key).toString());
    }
}

From source file:annualleave.PersonelTara.java

static public void Detection(int ilk, int son, String URL) throws FileNotFoundException, IOException {
    char gun[] = new char[100];
    int gunler[] = new int[32];
    for (int j = ilk; j <= son; j++) {
        gunler[j] = j;//  w ww  .java2s .c o  m
    }
    String oncekiAd;
    // C:\\Users\\talha\\Documents\\NetBeansProjects\\AnnualLeave\\src\\annualleave\\Mays 23.xlsx
    String excelFilePath = URL;
    FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
    Workbook workbook = new XSSFWorkbook(inputStream);
    Sheet firstSheet = workbook.getSheetAt(0);
    int sonuncuIndex = firstSheet.getLastRowNum();
    Iterator<Row> iterator = firstSheet.iterator();

    while (iterator.hasNext()) {

        Row nextRow = iterator.next();
        Iterator<Cell> cellIterator = nextRow.cellIterator();

        if (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            if (cell.getRowIndex() >= 6) {
                oncekiAd = ad;
                cell = cellIterator.next();
                cell = cellIterator.next();
                cell = cellIterator.next();
                ad = cell.getStringCellValue();
                cell = cellIterator.next();
                cell = cellIterator.next();
                tarih = cell.getStringCellValue();
                if (ad != oncekiAd && i != 0 && !(oncekiAd.equals("Personel Ad Soyad"))
                        && !(oncekiAd.isEmpty()) && !(ad.isEmpty()) && !(ad.equals("Personel Ad Soyad"))
                        || cell.getRowIndex() == sonuncuIndex) {
                    for (int j = ilk; j <= son; j++) {
                        if (gunler[j] != 0) {
                            GETIR[z] = oncekiAd + " " + gunler[j];
                            z++;
                            test = 1;
                        }
                        if (isBuilt) {
                            int left = tarih.indexOf(".");
                            int right = tarih.lastIndexOf(".");
                            String sub = tarih.substring(left + 1, right);
                            ay = Integer.parseInt(sub);

                            int left2 = tarih.lastIndexOf(".");
                            int right2 = tarih.lastIndexOf("");
                            String sub2 = tarih.substring(left2 + 1, right2);
                            yil = Integer.parseInt(sub2);
                        }
                        Build();
                    }
                    if (test == 1) {
                        yeniAd[c] = oncekiAd;
                        for (int j = ilk; j <= son; j++) {
                            if (gunler[j] != 0) {
                                Calendar date = Calendar.getInstance();
                                date.set(yil, ay - 1, gunler[j]);
                                if (date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
                                        || date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                                } else {
                                    yeniAd[c] += " " + gunler[j];
                                }
                            }
                        }
                        c++;
                        test = 0;
                    }
                    for (int j = ilk; j <= son; j++) {
                        gunler[j] = j;
                    }
                }
                if (!(cell.getStringCellValue().isEmpty()) && !(ad.equals("Personel Ad Soyad"))) {
                    int left = tarih.indexOf(0);
                    int right = tarih.indexOf(".");
                    String sub = tarih.substring(left + 1, right);
                    gunler[Integer.parseInt(sub)] = 0;
                    i++;
                }
            }
        }
    }
}

From source file:at.mukprojects.exclycore.dao.ExclyCoreReaderTest.java

License:Open Source License

/**
 * Tests the XLSXReader readStringCellValue function.
 *//* ww w . ja  v  a 2 s . c o  m*/
@Test
public void testXLSXReaderString() throws Exception {

    log.debug("Start test for testXLSXReaderString.");

    int counter = 0;
    ReaderTestImpl reader = new ReaderTestImpl();

    while (inputRowIterator.hasNext()) {
        Row inputRow = inputRowIterator.next();
        Iterator<Cell> inputCellInterator = inputRow.cellIterator();

        while (inputCellInterator.hasNext()) {
            Cell inputCell = inputCellInterator.next();

            log.debug("RowIndex: " + inputCell.getRowIndex() + " - RowExcel: " + (inputCell.getRowIndex() + 1));

            switch (counter) {
            case 0:
                log.debug("0 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("0", reader.readStringCellValue(inputCell).getData());
                break;
            case 1:
                log.debug("1 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("1", reader.readStringCellValue(inputCell).getData());
                break;
            case 2:
                log.debug("100 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("100", reader.readStringCellValue(inputCell).getData());
                break;
            case 3:
                log.debug("MuK / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("MuK", reader.readStringCellValue(inputCell).getData());
                break;
            case 4:
                log.debug("1.000,10 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("1.000,10", reader.readStringCellValue(inputCell).getData());
                break;
            case 5:
                log.debug("2.000 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("2.000", reader.readStringCellValue(inputCell).getData());
                break;
            case 6:
                log.debug("2 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("2", reader.readStringCellValue(inputCell).getData());
                break;
            case 7:
                log.debug("1.9 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("1.9", reader.readStringCellValue(inputCell).getData());
                break;
            case 8:
                log.debug("0,01 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("0,01", reader.readStringCellValue(inputCell).getData());
                break;
            case 9:
                log.debug("ExclyStringError: ture / " + reader.readStringCellValue(inputCell).isError());
                assertTrue("Should be an ExclyStringError.",
                        reader.readStringCellValue(inputCell) instanceof ExclyStringError);
                break;
            case 10:
                log.debug("Tue Oct 20 00:00:00 CEST 2015 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("Tue Oct 20 00:00:00 CEST 2015", reader.readStringCellValue(inputCell).getData());
                break;
            case 11:
                log.debug("10/10/2015 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("10/10/2015", reader.readStringCellValue(inputCell).getData());
                break;
            case 12:
                log.debug("- / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("-", reader.readStringCellValue(inputCell).getData());
                break;
            case 13:
                log.debug("42297 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("42297", reader.readStringCellValue(inputCell).getData());
                break;
            case 14:
                log.debug("500 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("500", reader.readStringCellValue(inputCell).getData());
                break;
            case 15:
                log.debug("#Text / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("#Text", reader.readStringCellValue(inputCell).getData());
                break;
            case 16:
                log.debug("1,00.01 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("1,00.01", reader.readStringCellValue(inputCell).getData());
                break;
            case 17:
                log.debug("WAHR / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("WAHR", reader.readStringCellValue(inputCell).getData());
                break;
            case 18:
                log.debug("  / " + reader.readStringCellValue(inputCell).getData());
                assertEquals(" ", reader.readStringCellValue(inputCell).getData());
                break;
            case 19:
                log.debug("Sun Jan 03 00:00:00 CET 2016 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("Sun Jan 03 00:00:00 CET 2016", reader.readStringCellValue(inputCell).getData());
                break;
            case 20:
                log.debug("20 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("20", reader.readStringCellValue(inputCell).getData());
                break;
            case 21:
                log.debug("20 / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("20", reader.readStringCellValue(inputCell).getData());
                break;
            case 22:
                log.debug("ABC / " + reader.readStringCellValue(inputCell).getData());
                assertEquals("ABC", reader.readStringCellValue(inputCell).getData());
                break;
            }

            counter++;
        }
    }
}

From source file:at.mukprojects.exclycore.dao.ExclyCoreReaderTest.java

License:Open Source License

/**
 * Tests the XLSXReader readDoubleCellValue function.
 *///from   w  w w .j  a va 2  s . com
@Test
public void testXLSXReaderDouble() throws Exception {

    log.debug("Start test for testXLSXReaderDouble.");

    int counter = 0;
    ReaderTestImpl reader = new ReaderTestImpl();

    while (inputRowIterator.hasNext()) {
        Row inputRow = inputRowIterator.next();
        Iterator<Cell> inputCellInterator = inputRow.cellIterator();

        while (inputCellInterator.hasNext()) {
            Cell inputCell = inputCellInterator.next();

            log.debug("RowIndex: " + inputCell.getRowIndex() + " - RowExcel: " + (inputCell.getRowIndex() + 1));

            switch (counter) {
            case 0:
                log.debug("0.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(0.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 1:
                log.debug("1.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(1.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 2:
                log.debug("100.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(100.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 3:
                log.debug("ExclyDoubleError: ture / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be an ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleError);
                break;
            case 4:
                log.debug("1000.10 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(1000.10, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 5:
                log.debug("2000.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(2000.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 6:
                log.debug("2.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(2.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 7:
                log.debug("1.9 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(1.9, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 8:
                log.debug("0.01 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(0.01, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 9:
                log.debug("ExclyDoubleError: ture / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be an ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleError);
                break;
            case 10:
                log.debug("42297.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(42297.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 11:
                log.debug("ExclyDoubleError: ture / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be an ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleError);
                break;
            case 12:
                log.debug("ExclyDoubleError: false / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be no ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleBlank);
                break;
            case 13:
                log.debug("42297.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(42297.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 14:
                log.debug("500.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(500.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 15:
                log.debug("ExclyDoubleError: ture / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be an ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleError);
                break;
            case 16:
                log.debug("100.01 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(100.01, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 17:
                log.debug("1.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(1.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 18:
                log.debug("ExclyDoubleError: false / " + reader.readDoubleCellValue(inputCell).isError());
                assertTrue("Should be no ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleBlank);
                break;
            case 19:
                log.debug("42372.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(42372.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 20:
                log.debug("20.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(20.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 21:
                log.debug("20.0 / " + reader.readDoubleCellValue(inputCell).getData());
                assertEquals(20.0, reader.readDoubleCellValue(inputCell).getData(), 0.0001);
                break;
            case 22:
                log.debug("ExclyDoubleError: ture / " + reader.readDoubleCellValue(inputCell).getData());
                assertTrue("Should be an ExclyDoubleError.",
                        reader.readDoubleCellValue(inputCell) instanceof ExclyDoubleError);
                break;
            }

            counter++;
        }
    }
}

From source file:at.mukprojects.exclycore.dao.ExclyCoreReaderTest.java

License:Open Source License

/**
 * Tests the XLSXReader readIntegerCellValue function.
 *///from w  w w .j a  va2 s  .c om
@Test
public void testXLSXReaderInteger() throws Exception {

    log.debug("Start test for testXLSXReaderInteger.");

    int counter = 0;
    ReaderTestImpl reader = new ReaderTestImpl();

    while (inputRowIterator.hasNext()) {
        Row inputRow = inputRowIterator.next();
        Iterator<Cell> inputCellInterator = inputRow.cellIterator();

        while (inputCellInterator.hasNext()) {
            Cell inputCell = inputCellInterator.next();

            log.debug("RowIndex: " + inputCell.getRowIndex() + " - RowExcel: " + (inputCell.getRowIndex() + 1));

            switch (counter) {
            case 0:
                log.debug("0 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(0, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 1:
                log.debug("1 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(1, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 2:
                log.debug("100 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(100, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 3:
                log.debug("ExclyIntegerError: ture / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be an ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerError);
                break;
            case 4:
                log.debug("1000 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(1000, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 5:
                log.debug("2000 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(2000, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 6:
                log.debug("2 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(2, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 7:
                log.debug("1 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(1, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 8:
                log.debug("0 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(0, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 9:
                log.debug("ExclyIntegerError: ture / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be an ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerError);
                break;
            case 10:
                log.debug("42297 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(42297, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 11:
                log.debug("ExclyIntegerError: ture / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be an ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerError);
                break;
            case 12:
                log.debug("ExclyIntegerError: false / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be no ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerBlank);
                break;
            case 13:
                log.debug("42297 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(42297, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 14:
                log.debug("500 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(500, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 15:
                log.debug("ExclyIntegerError: ture / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be an ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerError);
                break;
            case 16:
                log.debug("100 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(100, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 17:
                log.debug("1 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(1, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 18:
                log.debug("ExclyIntegerError: false / " + reader.readIntegerCellValue(inputCell).isError());
                assertTrue("Should be no ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerBlank);
                break;
            case 19:
                log.debug("42372 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(42372, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 20:
                log.debug("20 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(20, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 21:
                log.debug("20 / " + reader.readIntegerCellValue(inputCell).getData());
                assertEquals(20, reader.readIntegerCellValue(inputCell).getData());
                break;
            case 22:
                log.debug("ExclyIntegerError: ture / " + reader.readIntegerCellValue(inputCell).getData());
                assertTrue("Should be an ExclyIntegerError.",
                        reader.readIntegerCellValue(inputCell) instanceof ExclyIntegerError);
                break;
            }

            counter++;
        }
    }
}