As we all are aware reading and writing data from excel file is one of the most important aspects that we need to take care while designing our automation testing framework
Sometime During designing our test automation framework specially
while using the data-driven testing approach we came across requirements where we
need to copy the data from one excel file and paste it into another excel using
test automation.
so in this Section, we will learn how we copy-paste the data from
one excel file to another 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.
To know more about the Apache POI API and its components. Please
refer to this link.
To start working 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 below excel sheet named as Test
Data 1 and kept it on my Desktop.
Test Data 1.xlsx |
And all the data from this excel sheet I will do copy paste into
another excel named as Test Data 2 which is again placed on my desktop
Below is the complete
code snippet. All the important points are mentioned in the code itself which is
very much self-explanatory.
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.
Yes u can
ReplyHi Ankur Please let me know How to handle iframes in Page object model if you know please help me my mail id is venkypuli86@gmail.com
ReplyHI Ankur while copy pasting the sheet my current sheet got deleted . I want to keep my first sheet as it is
Reply