I am receiving data from an Excel file as a DataTable . From this DataTable, I need to extract the values from columns 3, 4, and 5 and update the corresponding fields in a table within a Word document.
Kindly assist with the best approach or solution to achieve this.
Read the Excel file into a DataTable, then loop through it and extract values from columns 3, 4, and 5 i.e indexes 2, 3, 4. Then write these in word table using Word Application Scope.
Ideally its advised to create a word template and use. instead of having table already in word ..keep a placeholder or bookmark and use it to insert the datatable in the order you need
My requirement is there is already table in the Word and i want to insert only 3 columns in between the Table in in the Word document, This 3 column data we are getting from the Excel.
Read the Excel using Read Range into a DataTable. Open the Word document with Word Application Scope. Get the existing table by index. Insert three new columns at the required position in the table. Loop through the Excel DataTable and use a row index to write values from columns 3, 4, and 5 into the new Word table columns using Set Text. Save and close the document at the end.
This requirement can be achieved using LINQ along with Word activities in UiPath.
First, read the Excel file into a DataTable using the Read Range activity. Since UiPath follows 0-based indexing, columns 3, 4, and 5 correspond to indexes 2, 3, and 4.
You can then use the below LINQ expression to extract only the required columns into a new DataTable:
After extracting the data, loop through dtSelected using a For Each Row in DataTable activity. Inside the loop, use Word Application Scope, retrieve the table using Get Tables, and update the corresponding cells using Set Text. A row counter can be used to map each Excel row to the correct Word table row.
This approach keeps the logic clean, readable, and easy to maintain.