Append right to left string to a Document in Java - append

I parse a HTML page to Document with Jsoup at "doc" variable. When I append a right to left string in Persian (سلام) to one of tags it appear as question marks. [ ?????? ]
How can I fix this problem?
Document doc = Jsoup.connect(url);
doc.getElementById("id_0").append("<p>سلام</p>");

Related

How to insert formated text into a merge field in word?

Ive got a word document with a lot of merge fields which look like this:
{ MERGEFIELD SOME_FIELD }
This works fine with unformatted text. But now I want to insert formated text this way. So the content of "SOME_FIELD" will be created out of Rich Text, including cursive and bold parts and newlines.
Is there a way to use merge fields where the formating comes out of the content of the related field. It does not have to be rich text.
All I found until now are solutions with automation. Like this: Word VBA macro to insert file and merge formatting
But this does not word for me because in the moment I write the content of SOME_FIELD I don't have access to automation.
SME_FIELD is set with access vba like this (in the example the formating is set with rich text but I can use another formating language too):
dim richText as string
richText = "Hey look, \b I'm bold \b0 and I'm not"
with CurrentDb.OpenRecordset("Select SOME_FIELD from SOME_TABLE")
Call .MoveFirst
!SOME_FIELD = richText
Call .Update
end with
I thought that there might be some other formating tags which word can read, but I did not find any.
It seems like its not possible to insert format information to word via a merge field.

Get string within a specific string

Please excuse the stupid question, but I am an absolute freshman in Crystal Reports.
I would like to add a plaintext to Crystal Reports. The problem is, if a hyperlink has been inserted that contains a display text, it will be displayed as follows:
HYPERLINK "http://google.de/https://www.google.com/webhp?hl=de&sa=X&ved=0ahUKEwipsMvN_-vkAhWCEVAKHf3JBCIQPAgD " google.com
I just want the hyperlink to be displayed within "
The result should be https://www.google.com/webhp?hl=de&sa=X&ved=0ahUKEwipsMvN_-vkAhWCEVAKHf3JBCIQPAgD
However, it is also possible that "hyperlinks" that do not contain a hyperlink may occur.
My professor has created an Access database that contains texts and hyperlinks and I have to display the hyperlinks correctly.
Some lines of the database:
HYPERLINK "http://votetandem.org/" votetandem.org
HYPERLINK "https://app.votetandem.org/"votetandem.org
Sometimes there is a space between "URL" display text and sometimes not
Use the REPLACE() function. Hit F1 for online help.
I found a solution for my problem. I created a formular field. chr(34) is " in ASCII
If InStr({TABLE},"HYPERLINK " & chr(34)) > 0 Then
Split({TABLE},chr(34))[2]
else
{TABLE}
the URL is the second entry. The first is Hyperlink, second real URL and the third the displayed name.

Is There a Way to do a Spanish/English MailMerge?

I have an SSRS report that has Spanish and English text boxes. If the dataset row is a Spanish speaking person, an expression in each Spanish textbox shows that and hides the English textbox. These textboxes are exactly placed over each other.
My boss wants me to use SSRS to generate an Excel spreadsheet from the dataset(this is not hard) and use Word template for a mail merge. However, I am having trouble trying to figure out if I can hide all English when row is a Spanish row and vice versa. These are health clients of Spanish and English nationality.
I can do mail merges attached to a Recordset, I can do one in English, one in Spanish. I am trying to avoid this and have it all in one Mail Merge.
Areas marked in red will change to Spanish translation and/or date format. The dates are a no-brainer I can use a conditional IIF, however the formatted body I have no solution for, based on value in Field "CL_Language" which is either "Spanish" or "English".
====================================
The merge fields for dates and greeting are easy. There is no merge field for the text. And yes, only option might be for 2 separate reports with different Recordsets.
It's not clear what the actual issue is but...
Instead of hiding textboxes, which could cause problems when exporting etc., why not set a single textbox to the correct language text using an expression?
Something along the lines of
=IIF(Fields!Language.Value = "English", Fields!MyEnglishText.Value, FieldsMySpanishText.Value)
I found a solution. But it could be very difficult for the client to create. It involves hitting Ctrl + F9 which will create curly brackets {}.
Inside those curly brackets an IF statement is placed and I just pasted the whole Spanish formatted body in the true area, and the whole English body in the false area.
{IF "CL_Language" = "Spanish" "spanish body text here" "english body text here"}
Very strange syntax and you need to right click on the area to see choices like "Toggle Field Codes" (IF statement get's hidden), "Edit Field", and "Update Field". With Edit Field and Update Field you get a popup with the fields in your recordset.
If you saw the examples in my question, you can see that is some big clunky text AND . . .inside of it is a merge field that works! The Excel recordset comes already with the month name in correct language for each row.
Since it is not smart to include links that might expire, I am including the Google text I used to find this solution. Then I took a chance on a huge formatted chunk of text with a merge field inside of it.
Google this: "If Merge Field then"
Now is this a viable solution for the client versus just having a Word template for each language?
I think this is too difficult and I even duck when running it. Also, once it's working, if I look at the toggled code, the Conditional field no longer says the field name, but the value in the field, go figure.
{IF "Spanish" = "Spanish" or {IF "English" = "Spanish" instead of {IF "CL_Language" = "Spanish" or {IF "CL_Language" = "English"
Here is how to access the fields using right click. (remember, your curly brackets HAVE to be created with Control + F9).

Merge field watermark - Microsoft Word 2013

I want to add a conditional Watermark in a word document using merge field. Is there any way to accomplish this? Is there any way to use merge field condition like below to add "DRAFT" watermark? or any other way to use a condition to make a watermark visible on the document? I am using Microsoft Word 2013. Thanks in advance for your help guys.
{ IF"{MERGEFIELD SampleField}"="Yes" "DRAFT" "" }
Yes, it's possible, with the caveat that you can't use Word's built-in Insert/Watermark functionality. An "If" conditional can work only with textual content. Word's built-in Watermarks are "WordArt" - which places an object in the document.
But you can use the Text Box drawing tool (as in Insert/Text Box/Draw Text box) to create the "container" for the watermark text in the document Header. It can be positioned anywhere on the page; make sure you set the text wrap formatting to "Behind text".
Insert the If field into that, with the nested mergefield and conditional statement. You need to type the watermark text and format it the way you want to have it.
The correct format:
{ IF { MERGEFIELD PrintCopy = 1 "ORIGINAL" "COPY" }}
Add spaces before and after the equal sign
Make sure the entire row (text above) is highlighted in grey when you click on it in the word document, otherwise it is only text once merged.

Add Variable Hyperlink in Mail Merge in Word 2013

I'm trying to add a hyperlink to a mail merge field. So something like this:
{HYPERLINK "{MERGEFIELD "Links" }"}
So I create a field like this.
{ MERGEFIELD Links }
And the above works (it displays different links for different recipients).
However, when I go to Edit Field, and then attempt to add HYPERLINK to { MERGEFIELD Links}, Word will not allow me. Meaning that when I type HYPERLINK followed by a space, the "variable" field is gone. Instead of word displaying...
LINK
it displays...
{HYPERLINK "{MERGEFIELD "Links" }"}
even after I press "update field". So Word is not letting me enter HYPERLINK for some reason.
How do I solve this?
From the Microsoft Web Site,
On the Insert menu, click Field (under Quick Parts in later office versions).
In the Field names list, click Hyperlink,
and then click OK. The text Error! Hyperlink reference not valid
appears in the document.
Press ALT+F9 to open the { HYPERLINK \* MERGEFORMAT } field code.
Put the insertion point after HYPERLINK and then add a space.
On the Insert menu, click Field. In the Field names list, click MergeField. In the Field name text box, type the name of the data source field that contains the hyperlink, and then click OK. For example, if the name of the data source field is "Address1," the field code appears as follows: { HYPERLINK { MERGEFIELD "Address1" } \* MERGEFORMAT }
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Put the insertion point at some arbitrary place in the middle of the Error! Hyperlink reference not valid text, and insert the text you want to appear. If you would like a merge field, insert that from the "Insert Merge Field" option on the menu.
Delete the remaining text of Error! ... before and after the text you want to keep.
Note: If your merge field only contains an identifier, with the URL to be provided as a static part of the merge document, this can work also. On Step 5, you will need to insert the URL text as well as the MergeField, for example:
{ HYPERLINK "https://www.myurl.com/EditForm.aspx?ID={ MERGEFIELD ID }" \* MERGEFORMAT }
I also have been struggling with this. What I found to be the key is creating the document from SCRATCH and not saving it before executing the mail merge. Here are the steps I used:
open a new document and click on the step by step mail merge wizard; add your generic text.
To add the variable hyperlink go to insert>quick parts>fields
select hyperlink on the left and click okay
Use alt + F9 to see the hyperlink field code
Type “” and between them insert your merged field so that {HYPERLINK \* MERGEFORMAT} -> becomes {HYPERLINK"{MERGEFIELD"Constructed_URL"}"\*MERGEFORMAT}
Press ALT+F9 to hide the field code
Click in the text "Error! Hyperlink reference not valid" and replace with something generic like click here.
Complete the mail merge BEFORE you save the document.
Hope this helps and good luck!
Start with the process here:
http://support.microsoft.com/kb/912679
However, like user1867326 indicated, the hyperlink (which should be variable with the mail merge) is converted into a static link when the Word file is reopened.
A solution that seems to work is adding a bookmark within the hyperlink field code immediatly after the mergefield.
{ HYPERLINK { MERGEFIELD "Link" } \* MERGEFORMAT }
Click between the } and \ and go to INSERT > Bookmark, give it a name, and this seems to prevent Word from replacing the mergefield with a static hyperlink.
This answer is adapted and hopefully clarified from the clever solution described here:
Mailmerge dynamic hyperlink fields lost after save/reload of document - Word 2010
This is what worked for me for an email mail merge with variable hyperlinks that all display the same text. I am using Office 2016 Word.
Put the insertion point where you would like the link display text to be in the document.
On the Insert menu, click Quick Parts, and select Field.
In the Field Names list, click Hyperlink, and then click OK. The text Error! Hyperlink reference not valid appears in the document.
Press ALT+F9 to open the { HYPERLINK * MERGEFORMAT } field code. 5. Put the insertion point after HYPERLINK.
On the Insert menu, click Quick Parts, and select Field. In the Field Names list, click MergeField.
In the Field name text box, type the name of the data source field that contains the hyperlink, and then click OK. For example, if the name of the data source field is "Address1," the field code appears as follows: { HYPERLINK { MERGEFIELD Address1 } * MERGEFORMAT }
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Put the insertion point just before the period in ‘Error! Hyperlink reference not valid text.’ and delete all the text except for the period. Write in the link display text. Make sure not to delete the period (this is important).
To check that the hyperlinks are mapping, right click on the link display text and click edit hyperlink. You will see the correct link in the address field for each record.
I like to style the period text color to white so it looks invisible.
I have had limited success with the other suggestions - basically, Word is buggy in this area. There is a simple alternative - indeed the only alternative AKAIK if you want the hyperlink to vary AND the text that is displayed to vary too (not an unreasonable requirement).
Note that this only works for DOCUMENT MERGES, not for EMAIL MERGES, since it relies on processesing the output document.
The trick is to add a place marker (text that serves as an ID) wherever you want a hyperlink. Insert this via a regular mergefield. In your table of source data, you need columns
place marker, text_for_display, hyperlink
You then need to put your source data into Excel (if that isn't where you have it already) and put this formula
="Set Rng = ActiveDocument.Content: Rng.Find.Execute FindText:="""&[place marker]&""": ActiveDocument.Hyperlinks.Add Anchor:=Rng, Address:="""&[hyperlink]&""", TextToDisplay:="""&[text_for_display]&""""
into a blank column in the first row, and fill down.
You need to amend [place marker],[hyperlink] and [text_for_display] to the appropriate cell references.
If the [hyperlink] includes a query string, you may find you want to build it using a formula, based on other data in the source.
The resulting formulae can then be pasted into a macro and run on the output document.
You may then want to use the "Robbins/Mayor" macro http://www.wordbanter.com/showthread.php?t=18346 to split the generated documents.
I got this working thanks to this thread, but then it stopped working and I figured out why so I thought I'd say thanks by posting what I discovered here.
The issue is that word has a special type of curly brace. Copying the code text from this thread may not work for that reason. To get the curly braces Word wants, I used Fn + Command + F9 on my Mac running Catalina and Office 365. Apparently some Mac users may find Command + F9 works -- just test to find out. I'm sure Windows has a similar keystroke set. I found the Mac solution in this post.
Also, the syntax that works for me is: { HYPERLINK { MERGEFIELD "url" } * MERGEFORMAT } where "url" is the label of the column with the link in my Excel file. Note the position of the quotes. This differs from other posts here (I tried the other combinations) but I wouldn't be surprised if the syntax may vary across Word versions and operating systems.
To get this method to work in Mac Office 365 (Big Sur), you need to know about the Toggle Field Codes in the context menu. The shortcut above to replicate the Alt-F9 behavior will create a new field, instead of allowing you to edit the field that exists.
At these steps:
Press ALT+F9 to open the { HYPERLINK * MERGEFORMAT } field code.
OR
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Instead of the keyboard shortcut, right click on the error message and select Toggle Field Codes from the context menu.
Answer worked great for me with this adjustment! Thank you!