How to write data in an excel file?

In order to write data in an excel file, we make use of column name.

Lets say we have a sample excel file as shown below in which you want to write data at some specific cell.

If you want to write data as username or country at a specific index we will use its column name.

To achieve this please follow the steps below:

Step 1: Load the excel file using loadexcel function.

Once you load an excel file all the data of the file is now present in the alias name.

Step 2: Define a variable and use setcellvalue function to set the data at specific cell in the excel sheet using alias name defined in step one.

Here, Adam is the data that we want to write in the excel sheet at 3rd index. After completing this step and executing this test case it will write the data in the excel sheet.

Similarly you can set the data of any column based on its column name and index.

Note: When you are writing data in any excel file make sure excel file is closed.

Was this page helpful?