CRUD -> Read excel content then print out

Code Source:

   XSSFSheet sheet = workbook.getSheet("Sheet1");

            Row currentRow = sheet.getRow(i);

            Cell currentCell = currentRow.getCell(j);

            currentCell.getStringCellValue();

    @Then("^I print the data inside the workbook$")
    public void i_print_the_data_inside_the_workbook() throws Throwable {

        System.out.println("Printing Excel Workbook data from Sheet1 after adding data.......");
        try
        {

            XSSFSheet sheet = workbook.getSheet("Sheet1");
            for(int i=0;i<sheet.getPhysicalNumberOfRows();i++)
            {
                Row currentRow = sheet.getRow(i);
                for(int j=0;j<currentRow.getPhysicalNumberOfCells();j++)
                {
                    Cell currentCell = currentRow.getCell(j);
                    System.out.print(currentCell.getStringCellValue() + "\t");

                }
                System.out.println("\n");

            }

            }

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

 

posted @ 2018-01-11 14:21  thisissweetcandy  阅读(63)  评论(0)    收藏  举报