Writing Specific Value from excel using Apache POI in Selenium WebDriver


Writing Specific value from excel using Apache POI in Selenium WebDriver

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




SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
August 31, 2019 at 5:39 PM

Hi Ankur,
Thanks 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.

Reply
avatar