Pass carriage return to MS Word from string

word
studio

#1

Hi,

I have a string containing a postal address in the following format:
“17 abc street, town, postcode”

And I want to enter this address into Word as follows:
17 abc street
town
postcode

So far I am trying the following:
addressLines=Split(AddressLine, “,”)

And then a For each loop where I want to parse the separate lines with a carriage return (char(13)), which then will be copied into a Word file.

Does anyone have an idea how to pass my address lines in this format to Word? Or does anyone have a better suggestion than mine?

thanks,
Jan


#2

Hello @Jav_van_Eijck

You could use AddressLine.Replace(",",Environment.NewLine)

Regards,
Susana


How to replace special characters with new line?
#3

Thanks! You’re a star!

Initially I had tried with various replace trials (“char(13)”, “/r/n”), but none of them worked.

Environment.NewLine… who would have thought it could be that simple :slight_smile:


#4

jajaja @Jan_van_Eijck , This has happened to me like a thousand times! :grinning:
Susana,


#5

Hi,

Sadly, Environment.NewLine doesn’t work when the text is in a table cell. I found a few alternatives for VBdotNet or C#, but I’m not able to make it works with UIPath :

Has someone a solution ?


#6

@pierreg, this is a workaround, not a solution. I am thinking we need a complete UiPath.OfficeOpenXML.Activities, any thoughts? I believe the Word activities so far are based on DocX, which is easier to use but has less functionality than OOXML, IMHO.

Instead of fields, which threw exceptions for me, I have used bookmarks in the table cells. I realize this may defeat your purpose.

There’s a backup of the target doc included in the archive for experimentation purposes.

Anyway, here goes…

Regards,
burque505

MS_Word.zip (29.8 KB)


#7

Thanks @burque505 for your help, but UIPath support team told me the perfect and simple solution : instead of adding Environment.Newline to my string (where I want a line break), I add “^p” : it’s the newline character in Word.


#8

@pierreg, thanks for sharing that! That will help me out as well. If you could post a line of your code that shows how that’s actually implemented I’d really appreciate it.

I got some other tips from this link that might come in handy also. For example, I just tried both ^p and ^013 in a test doc, and got the same results for either.

Regards,
burque505