Home › Forums › Software Testing Discussions › Validating excel files using java……….
- This topic has 4 replies, 5 voices, and was last updated 6 years, 7 months ago by Alin.
-
AuthorPosts
-
August 25, 2017 at 3:31 am #17237
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…
September 4, 2017 at 9:36 am #17296One common solution that I have heard of is to insert the formulas in the cells through JAVA?
That might work?
September 5, 2017 at 1:41 pm #17317Normally 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.
September 10, 2017 at 3:11 am #17352Apache POI may help to read and write Excel files using java…
September 14, 2017 at 9:48 am #17399Hi 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 -
AuthorPosts
- You must be logged in to reply to this topic.