As we all are aware of reading and writing data from an excel file is one of the most important aspects that we need to take care of while designing our automation testing framework especially while using a data-driven testing approach.
So
in this Section, we will learn how to write/update any single cell into excel
file.
Apache POI API is an open-source library created by Apache Software that allows us to create, modify and work with other Microsoft Office Product.
Know more about the Apache POI API and its components. Please refer to this link.
So to start working and writing any specific value into an excel sheet we first need to download Apache POI maven dependency or JAR. Please click on this link to download this from the maven repository.
In this Section, I am using below maven dependencies.
For Demo purpose, I have created the below excel sheet that already contains some data and kept it on my Desktop.
In this blog, I am creating one generic utility Named “setCellValue” that can be called anywhere by just passing text that needs to write in excel file along with row and column number of the excel file into which we wanted to write/update data.
Below is the complete code snippet in which I am updating the text "Automation" in the third row and second column of the excel sheet.
Result of above code execution is
Hi Ankur,
ReplyThanks for the blog, it is very useful to me.
I want to know can we achieve this using Workbook factory so we dont need to use XSSFSheet etc.
Thanks in advance.