Generalized Apache POI script for reading and writing to .xlsx files
In this post, we will be looking to simplify the script mentioned in this post . Below script is generalized version so it can be used by other classes for reading and writing to .xlsx files. The code for reading and writing to .xlsx is made modular by putting them in different class and making read and write methods static. Any test that needs to read from excel file can just call the readFromXLSX() method and similarly any test that needs to write data to excel file, can just call the writeTestResultToXLSX() method and passing the appropriate parameters to it. Here's the class that contains the read and write methods: Below code makes use of Enumerations to restrict the value of test result to be either PASS or FAIL. This would make TestNG tests that will use these methods, not to write illegal values into the excel sheet. import java.io.File ; import java.io.FileInputStream ; import java.io.FileNotFoundException ; import java.io.FileOutputStream ; import java.