Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在excel中逐行打印传递的字符串_Java_Selenium_Katalon Studio - Fatal编程技术网

Java 如何在excel中逐行打印传递的字符串

Java 如何在excel中逐行打印传递的字符串,java,selenium,katalon-studio,Java,Selenium,Katalon Studio,我正在excel中打印一些字符串值 在excel中,当前正在打印最后一个字符串,但我需要逐行打印它们 代码 关键词 @Keyword public void demoKey(String name) throws IOException{ FileInputStream fis = new FileInputStream("C:\\Users\\lahiruh\\Katalon Studio\\Project Decypha\\Decypha data files\\D

我正在excel中打印一些字符串值

在excel中,当前正在打印最后一个字符串,但我需要逐行打印它们

代码

关键词

@Keyword
    public void demoKey(String name) throws IOException{

        FileInputStream fis = new FileInputStream("C:\\Users\\lahiruh\\Katalon Studio\\Project Decypha\\Decypha data files\\Demo1.xlsx");
        XSSFWorkbook workbook = new XSSFWorkbook(fis);

        XSSFSheet sheet = workbook.getSheet("Sheet1");
        int rowCount = sheet.getLastRowNum()-sheet.getFirstRowNum();
        Row row = sheet.createRow(rowCount+);
        Cell cell = row.createCell(0);
        cell.setCellType(cell.CELL_TYPE_STRING);
        cell.setCellValue(name);
        FileOutputStream fos = new FileOutputStream("C:\\Users\\lahiruh\\Katalon Studio\\Project Decypha\\Decypha data files\\Demo1.xlsx");
        workbook.write(fos);
        fos.close();
现在我可以得到如下输出(覆盖每个值并给出最后一个字符串)


我想知道你必须按照以下方式来做

  • 首先创建一组行
  • 创建单元格并定义单元格数据类型
  • 将值存储在单元格中
  • 我在下面提供了逐行存储数据的结构

    int rowNumber = 0; // Row number starting with 0
    
    for (i = 0 ; i < 10 ; i++) { //This for loop can be your data set
    
        Row row = sheet.createRow(rowNumber++);
    
        int columnNumber = 0; //Cell or Column number starting with 0
        for (j = 0 ; j < 5 ; j++) { //This for loop can be your data set
           Cell cell = row.createCell(columnNumber++);
           cell.setCellValue("Some string value");
        }
    }
    
    int rowNumber=0;//以0开头的行号
    for(i=0;i<10;i++){//这个for循环可以是您的数据集
    Row Row=sheet.createRow(rowNumber++);
    int columnNumber=0;//单元格或列编号以0开头
    for(j=0;j<5;j++){//这个for循环可以是您的数据集
    Cell Cell=row.createCell(columnNumber++);
    setCellValue(“某些字符串值”);
    }
    }
    
    试试这个

    for(int i = 0; i < arrOfStr.size(); i++)
    {
        String a = arrOfStr[i];
        System.out.println(a);
        //CustomKeywords.'WriteExcel.demoKey'(a)
        CustomKeywords.'WriteExcel.demoKey'(a,i)
    }
    

    这里的问题是什么?我需要一行一行地打印值,目前,它在同一行打印并相互覆盖
    for(int i = 0; i < arrOfStr.size(); i++)
    {
        String a = arrOfStr[i];
        System.out.println(a);
        //CustomKeywords.'WriteExcel.demoKey'(a)
        CustomKeywords.'WriteExcel.demoKey'(a,i)
    }
    
    public void demoKey(String name, int index) throws IOException{
    
            FileInputStream fis = new FileInputStream("path");
            XSSFWorkbook workbook = new XSSFWorkbook(fis);
    
            XSSFSheet sheet = workbook.getSheet("Sheet1");
            Row row = sheet.createRow(index + 1);
            Cell cell = row.createCell(0);
            cell.setCellType(cell.CELL_TYPE_STRING);
            cell.setCellValue(name);
            FileOutputStream fos = new FileOutputStream("path");
            workbook.write(fos);
            fos.close();
        }
    }