需要按预期将长字符串值发送到excel

问题描述 投票:0回答:2

我正在以(控制台视图)this的形式获取字符串值,我的输出是(excel)here,我需要在excel中将输出视为this。任何解决方案?

关键字

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

        FileInputStream fis = new FileInputStream("C:\\Users\\\\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+1);
        Cell cell = row.createCell(0);
        cell.setCellType(cell.CELL_TYPE_STRING);
        cell.setCellValue(name);
        FileOutputStream fos = new FileOutputStream("C:\\Users\\\\Decypha data files\\Demo1.xlsx");
        workbook.write(fos);
        fos.close();

测试用例

String str = arrlist.toString();
str = str.replaceAll("[\\[\\]]", "");
System.out.println(str);
String listString = String.join(", ", str);
String[] arrOfStr = listString.split("\\|");
CustomKeywords.'WriteExcel.demoKey'(listString)
for (String a : arrOfStr)
System.out.println(a);
java katalon-studio
2个回答
0
投票

您基本上是将整个字符串传递到单元格。因此,它在单个单元格中打印整个字符串。将字符串溢出直到,,然后在单元格中打印前8个值,然后增加行数,并为下一个单元格打印下一组8个字符串。


0
投票

如下所示在for循环内调用demoKey方法。

for(String a:arrOfStr)
{
    System.out.println(a);
    CustomKeywords.`WriteExcel.demoKey'(a);
}
© www.soinside.com 2019 - 2024. All rights reserved.