I am trying to generate datatable from a text file where the delimiters or separators are space, tab, newline, colon, or long “-” and write it into an excel file? What is the possible solution for this one?
Kindly see attached file for the sample input and target output file. Thank you.
→ You can use the Read CSV activity to read the text file and store the data in a datatable.
→ Open the Properties of Read CSV activity and Select the option based on your requirement in the Delimeter.
→ After Read CSV use the Write Range workbook activity to write the datatable to excel.
It looks like SAP Data output as text file. I would advise to get it from SAP in the form of xls. Text with Tab option outputs the report in xls format.
Decoding this text file to a table format will not be reliable.
Yes that’s good. One approach I would suggest for this would be,
Read text file to a string variable
Split the string by NewLine character. This will give us array of string.
Iterate the array using For Each activity.
Add else if activity inside the loop to check which line being iterated.
Define the conditions to split the currenttext variable based on your template.
for example:
first line have : as separator. Split the currenttex variable by : and it will give us string array. Just pass his array to a Add data row activity. this will add a row to datatable variable
Once we have the data in Datatable, use Append range activity to write the data we extracted from that particular line to excel file.
Continue till you get ** End of Listing**
I would have helped with the code but, don’t have this much time. Hope you will get this.
Feel free to reach if stuck somewhere.
Add logic before generate datatable to rename one string with some additional character like space, ', or anything which will not change the meaning of the column for business.