How can I automictically change files that contain values that is in dictionary

How can I automictically change files that contain values that is in dictionary.

E.g. I have a key which is and value “ABC”, and a few docx how do I change to “ABC” if the key exist in one of these files and if so there is multiples same in a file so how do I change all same at once.

@superpunchypp

Can you please wxplain a little or show some screenshots

Cheers

Hi @superpunchypp ,

Could you check the below workflow :
Word_Replace_Text.zip (20.7 KB)

It is not a dictionary implementation and maybe a bit more requirement was handled than what was needed, but it does explain about the looping with Key-Value replacement being done in the Word document or the Word document copy.

Let us know if it was possible for you to shift to the Dictionary implementation or if it is not the required logic would request if you could provide the Sample Input documents and the Expected output required, we should be able to implement in a similar manner.

  • For Each in yourDict.Keys
    ** replace CurrentItem (assuming the key represents the text to replace) with value yourDict(CurrentItem)

@superpunchypp

If the identifier on left is present in the docs…then use for eqch row in datatable or excel and then for each file in folder…then use word file activity and inside it replace text activity …

This will check for eqch identifier if the required value is present in word it would replace

Cheers

@superpunchypp

  1. Use excel file activity
  2. For each row in excel activity and give the sheet where all values are present
  3. For each file in folder and give the folder where the word files are present
  4. Use word file activity and give currentfile.fullname as filepath
  5. Replace text activity from word activities and use currentRow(0).StringValue in place of where to replace
  6. In palce of what to replace use currentrow(1).StringValue

Cheers

1 Like

could you explain more ty

do you have example files?

@superpunchypp ,

If you could provide us with the Sample documents on what is available to you as Inputs and what is the Transformation or output needed, we would be able to help you faster.

An initial idea was providing in the workflow provided.

@superpunchypp ,

Could you check with the below Workflow :
Word_Replace_Text.zip (50.1 KB)

The Input documents are placed in Input Files folder, After Execution it creates another Folder called as Output Files and will have the updated documents in it.

Let us know if this does not work as expected.

I’m not sure what more there is to explain. You use a For Each to loop through the keys, then you replace the values using CurrentItem from the loop.


may i know which package do i need to install

@superpunchypp ,

Could you update the dependencies/packages to the latest stable versions and check ?


all of it is updated

@superpunchypp ,

That is strange. Could you let us know if the Project workflows were moved to your Project workflow or was it opened from the Project which was sent ?

However, It might be the cause of Windows compatibility, as the one which was sent was built on Legacy.

Do check with this updated version converted to Windows :
Word_Replace_Text_Windows.zip (50.2 KB)

May i ask if you could explain, how do you do it without dictionary method?

@superpunchypp ,

Since the Datatable or the Excel sheet was also arranged in a Dictionary (Key-Value pair) manner, we didn’t have to convert it to a Dictionary again, as each row in the Excel sheet is as same as one Key-Value pair in Dictionary, we could loop through the rows present in the Excel sheet one by one and perform the substitution, this is also assuming that all the Keys present in the Excel is Unique.

could you explain the variables too, thanks

Also may i ask why some key did not change while other does?

@superpunchypp ,

  1. Reading the Master Excel sheet and getting the Output as Datatable (DT) and creating the Output Files folder. So that we can keep the input files as is and create separate output files in a different folder.
    image

  2. Next, We are looping through the Input Files folder using For Each File in Folder activity and fetching only files with extension as .docx
    image

  3. Inside the For Each File in Folder activity, each file is retrieved and we are preparing the OutputFilePath variable value and copying the input file to the Output file path location.
    image

  4. Next, we are looping through the rows of Master Excel Datatable and using the Replace Text in Document activity to perform the replace of Placeholders in Document which is present as keys in Master Excel sheet with the Mapped Values column.
    image

Taking the below as a Small Example :
image

Each row/CurrentRow variable value will have the set data mapped {Key,Value}, so the Value Corresponding to the Key <COMPANY NAME> will be 1, and it is accessed by CurrentRow("Value").ToString.