CRUD -> Create excel then update contents

PARM arg1=Random.xlsx will be passed during runtime

Source Code:

        workbook = new XSSFWorkbook();

  //Add a worksheet
        XSSFSheet sheet = workbook.createSheet("Sheet1");

        XSSFRow row = sheet.createRow(0);

  row.createCell(0).setCellValue(new Faker().name().firstName());

 

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

 

    @When("^I create the excel worbook \"(.*?)\"$")
    public void i_create_the_excel_worbook(String arg1) throws Throwable {
        workbook = new XSSFWorkbook();
        //Add a worksheet
        XSSFSheet sheet = workbook.createSheet("Sheet1");
        //Create two rows and add content in first 3 cells of each row
        for(int i=0;i<2;i++)
        {
            XSSFRow row = sheet.createRow(i);
            row.createCell(0).setCellValue(new Faker().name().firstName());
            row.createCell(1).setCellValue(new Faker().address().streetAddressNumber());
            row.createCell(2).setCellValue(new Faker().phoneNumber().phoneNumber());
        }
        FileOutputStream fout = new FileOutputStream(arg1);
        workbook.write(fout);
        fout.flush();
        fout.close();
    }

 

Future Definition

Feature: Demonstrate CRUD operations with Excel and read data from excel into a web form

  Scenario: Create, update excel workbook,add data and delete data
    When I create the excel worbook "Random.xlsx"
    Then I print the data inside the workbook
    And I perform delete operations on a workbook

 

posted @ 2018-01-11 13:22  thisissweetcandy  阅读(60)  评论(0)    收藏  举报