Unable to keep original formatting after performing string manipulations

hi @Florent_Salendres @aksh1yadav :grinning:
i have two wordfiles (wordfile1 & wordfile2) as attached screenshot

first i am copying contents to clipboard then performing simple string operations like replace a particular text
then i am just pasting into 2nd word file but i am getting output as formatted like line colours are changed also text type is changed

what can we do to keep the original formatting


wordfile1

image
wordfile2

Main.xaml (8.2 KB)

CopyTextAndStyle.zip (29.9 KB)

@Vikram212

You are right, Clipboard string manipulation erase the style.

Please try the attached alternate workflow.
It will copy the content of the first doc, paste it to the second doc and replace some text.

1 Like

Thanks
it was general approach but what if we need to use such task in Web/CRM automation
and what if we have multiple texts to replace

for example: take email automation where we have so many templates to pick one according to the request
then do the editting by replacing some dynamic texts

Is it possible ?

Hi @Vikram212

Could you have a look on this workflow based of GetClipboard Text & SetClipboard with RTF format?
RTF Stuff.xaml (6.0 KB)

You could also give a try with the HTML format from the clipboard (you need to change the RTF constants inside workflow.

To test it, just copy something in the clipboard with formating containing “test”, it should replace it with new values, preserving the format.

I guess the post bellow is about the same issue?

Cheers

3 Likes

Thanks @Florent_Salendres
i tried this code - but it worked.

:grin:

just silly questons

What should be Target object in Invoke Method why it is blank ?
For HTML - Do you mean i need to replace system.windows to system.html or is it something else
What is RFD constants ?

I meant rtf, sorry.

Regarding the constants, I meant you can change the expression on both Set and Get Clipboard methods to handle different format, in case your use case would be HTML related. image

The target object can stay blank when you refer to a Static method, I am giving some detailed explaination on the post bellow

Does it work for your case or not? not sure I understand :slight_smile:

Cheers

1 Like

Cool stuff!

1 Like

Thanks Very much @Florent_Salendres
For HTML- Invoke Method name & Target Type should be same ?

or should be anything else ?

Yes, just TextDataFormat should be changed.

Cheers

@Florent_Salendres
i changed textdataformat.rtf to textdataformat.html
and everything else is same still i am not getting output in CRM mail body

i checked in writeline:- strRTF
output shows in html format

Did you change it on both activities?

  • SetClipboardTextToRTF
  • Invoke Method (within the parameters)

If yes, there is a chance your CRM app do not recognize those format, that’s tedious to know without having access to the app itself.

Cheers

Did you change it in both places - in Assign activity and InvokeMethod activity?

Cheers

no worries…i will try some other ways
anyways thanks

Hi Florent, i am trying to use your method to fill out some html and i use the string.format to replace my placeholders with values, but once i do that all the html dissapears and i only have the value left.

Does this solution work with string.format when the string is in html format?