Word Manuplations

Hi Team,

I need support with the following requirement:

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.

Thanks in advance for your support.

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.

Thanks for the response. how can we identify the exact column in the word.

Thanks

Refer this. It may help.

Activities - Manipulate Word Documents

6. UiPath | Insert DataTable in Document | Pass Data from Excel to MS Word | UiPath Word Automation

SS 3

@srinusoft37

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

cheers

Thanks for the response

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.

Thanks

Hi @srinusoft37 ,

Try this

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.

Hi thanks for the response

Do we have any activity to identify the index and inserting of the column in the Word document in UiPath.

Could you please provide me the all the steps.. Please

Thanks

Steps in UiPath Studio:

  1. Open Word document using Word Application Scope

  2. Use Get Tables activity to get all tables and pick the required table by index

  3. To identify column position, note that Word tables are 1-based (first column = 1)

  4. Use Insert Column activity
    – TableIndex: the table number
    – ColumnIndex: position where you want to insert
    – InsertPosition: Before or After

  5. Repeat Insert Column three times if you need to add three columns

  6. Use For Each Row on the Excel DataTable with a row counter

  7. Use Set Text activity to write Excel columns 3, 4, and 5 into the new Word table columns using row and column indexes

  8. Save and close the document

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:

dtSelected = dtExcel.AsEnumerable().
Select(Function(r) dtExcel.Clone().Rows.Add(
r(2).ToString,
r(3).ToString,
r(4).ToString
)).CopyToDataTable()

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.

Thanks.