Мне нужно распечатать данные Excel из двух столбцов в sequeal fromat. первый столбец имеет одно значение Vaue, а другой столбец много значений - PullRequest
0 голосов
/ 25 апреля 2020

Я хотел прочитать данные из листа Excel, в котором первый столбец имеет одно значение, а в другом столбце для многих значений, таких как нежелательные значения, необходимо напечатать значение первого столбца со значением второго столбца в последовательном формате. Я не мог понять, как. Я использую # java # apache -poi #selenium

Данные Excel - это изображение: снимок экрана Excel

    public static void main(String[] args) throws Exception {

        // Step 1: Open the excel workbook
        XSSFWorkbook wbook= new XSSFWorkbook("C:\\Selenium\\Data\\Mydata.xlsx");
        // Step 2: Go to the Sheet
                XSSFSheet sheet= wbook.getSheet("Reg Types");

                // Step a) Get the number of the rows of the sheet
                int rowCount = sheet.getLastRowNum();
                System.out.println("The row countof the regtype: "+rowCount);
                // Step b) Get the number of the columns of the sheet
                int colCount = sheet.getRow(0).getLastCellNum();
                System.out.println("The column countof the regtype: "+colCount);

                    for (int i=1;i<=rowCount; i++)
                    {
                        // Step 3a: Go to the regtypecolumn
                        XSSFCell  regType= sheet.getRow(i).getCell(0);
                        // Step 3b: Save the value of the  regtype
                        String regTypeValue = regType.getStringCellValue();
                        //4 Print regtype and create query
                         System.out.println(regTypeValue);

                        // Step 5: Go to the optioncolumn junk values
                        XSSFCell  option= sheet.getRow(i).getCell(15);
                        // Step 5a: Save the value of the  option 
                        String optionValue = option.getStringCellValue();
                        String trimOptionValue=optionValue.replaceAll("\\s+","").replaceAll(",", " ");
                        //4 Print option and create query
                        System.out.println(trimOptionValue);

                    // Step 6: Close the workbook
                    wbook.close();              
    }
}
}


[Current output is][1]


[Expected output][2]


  [1]: https://i.stack.imgur.com/kjS6y.png
  [2]: https://i.stack.imgur.com/YMQrF.png

Токовый выход

001 AFD PB_P PB_DL EGS_D1 EGS_D2 PC01 PC02 PC04M WRE C

10A AFD PB_P PB_DL EGS_D1 EGS_D2 PC01 PC02 PC03 PC04 PC01M PC02M

1011 * AF * Ожидаемый выход

001 PB_P

001 PB_DL

001 EGS_D1

001 EGS_D2

10A AFD

10A PB_P

10A PB_DL

10A EGS_D1

10A EGS_D2

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...