Validating excel files using java……….

Home Forums Software Testing Discussions Validating excel files using java……….

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17237
    Nanda
    Participant
    @pattar75

    Hi,

    I have excel files with 2 sheets.  Need to compare a row of 1 sheet row in second sheet and display value if same.using Java.

    Require suggestion/inputs…

     

     

    #17296
    Ronan Healy
    Keymaster
    @ronan

    One common solution that I have heard of is to insert the formulas in the cells through JAVA?

    That might work?

    #17317
    Tassawer
    Participant
    @tassaweramin

    Normally VBA is used as backed programming language for excel, may be you can google for some VBA code to get an idea how this compression should be performed.

    #17352
    Archana
    Participant
    @archana

    Apache POI may help to read and write Excel files using java…

    #17399
    Alin
    Participant
    @groza-alin88

    Hi Nanda,

    You have to use apache POI. Below you can see a very simple example to start from (it is not complete; you have to add some more validations / data handlings):

            String excelFilePath = "D://ExcelFile.xls";
            FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
            Workbook workbook = new HSSFWorkbook(inputStream);
    
            Sheet firstSheet = workbook.getSheetAt(0);
            Sheet secondSheet = workbook.getSheetAt(1);
    
            for (int i = firstSheet.getFirstRowNum(); i <= firstSheet.getLastRowNum(); i++) {
                HSSFRow rowFirstSheet = (HSSFRow) firstSheet.getRow(i);
                HSSFRow rowSecondSheet = (HSSFRow) secondSheet.getRow(i);
    
                for (int j = rowFirstSheet.getFirstCellNum(); j < rowFirstSheet.getLastCellNum(); j++) {
                    HSSFCell cellFirstSheet = rowFirstSheet.getCell(j);
                    HSSFCell cellSecondSheet = rowSecondSheet.getCell(j);
                    if (cellFirstSheet.toString().equals(cellSecondSheet.toString())) {
                        System.out.println(cellFirstSheet.toString());
                        //or use any other display way like logs, files, reports etc.
                    }
                }
            }
            workbook.close();
            inputStream.close();

    Regards,
    Alin

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.