Read Data from Excel and Write it to a Text file

Read Data from Excel and Write it to a Text file

Excel-related automation is the widely used automation that is widely used in the industry. We first begin with opening an excel sheet, reading the data inside it, and writing that data to a text file.

  • Open an excel sheet that contains some data Use the "Launch Excel" function available under Excel action.

image.png

Launch Excel parameter should be selected as "Open the following document" which indicates that we are opening an Excel that already exists. Document Path should contain the path where the file exists. This action will automatically produce a variable "ExcelInstance" which can be used for various purposes.

  • Read data from Excel Sheet Use the "Read from Excel Worksheet" function available under Excel action.

image.png

Excel Instance parameter will be pre-filled with the instance name, in this case, "ExcelInstance". Retrieve parameter should be selected with the data that should be selected from the sheet. We shall select all the data present in the sheet, so use the option "All available values from worksheet". This will again produce a variable "ExcelData" which contains the data that is retrieved from the sheet.

  • Write data to a text file Use the "Write text to file" function available under File action.

image.png

File path parameter should contain the path of the text file on which data will be written. Note that if the file doesn't exist, it will be automatically created. Text to Write parameter should contain the variable which holds the data to be written, in this case, "ExcelData" If file exists parameter should be selected as "Overwrite existing content" to make sure that any previous data inside the text file will be deleted. Encoding parameter can be selected as Unicode.

  • Close Excel Use the "Close Excel" function available under Excel action.

image.png

Excel instance parameter will be pre-filled with the instance name, in this case, "ExcelInstance". Before closing the excel parameter can be selected as "Do not save document" if no changes are made to the excel sheet.

Run the automation flow and the resulting text file should contain all the data that the original excel file has.