Mailmerge single image into a Word Document based on a cell value - ms-word

I'd like to include an image into a mail merged word document based on the presence of a single value in a column which contains several values.
e.g. if the cell contains the value BOB insert image, if it contains any other value then do nothing.
Most of the {INCLUDEPICTURE} functionality seems built around including a different image based on a filename matching a cell value.
{INCLUDEPICTURE} "MERGEFIELD Selection_identifier).png"\*
MERGEFORMAT \d }
Works provided I translate selection_identifer in the spreadsheet itself, but there has to be a better way. There seems to be little information about this particular usecase online.

If you are only using a single image and it does not vary between merges, you should probably just use
{ IF "{ MERGEFIELD Selection_identifier }" = "BOB" "<the_image>" }
where <the_image> is a copy of the actual image, sized how you want, pasted between those quotation marks. In that case, there would be no need for an INCLUDEPICTURE field or a reference to an external image file.
As usual, all the {} have to be the special field code brace pairs that you can insert on Windows Desktop Word using Carl-F9 or similar.

Related

How to generalize special entities

We use Apache UIMA Ruta for processing our documents. The input documents contains all kind of patterns that we try to recognize and translate to a hierarchy of annotations.
One of the things we will do with the result is to decorate the input text with links. For that it's import that we know the original position information of the found annotations.
Some of the annotations are based on value lists. We use MarkTable to resolve them.
The problem we have is that input document can contain different kind of special entities. For example, the document can contain also words that contain entities like & 𝌆. These can also exist in words / sentences that will be looked up into valuelists.
We are searching for an option to generalize (convert) all that kind of options to a normal "plain text" format, so that we don't have to add all kind of options, with special entities to the valuelists.
Doing a pre-processing of the document and replace them all (for example with the HTMLConverter engine) is AFAIK not a good option, because that will also change the position info. & should match on &, but still seen as size 5.
I tried to use the replace action, that will add an extra "replacement" attribute to the annotation. When I add an interceptor (aspect) to the getCoveredText of the annotation class, and return replacement instead of real text if available, the matching will succeed. But this give problems if the replacement text contains spacers (the end position is still equal with the original text / first RutBasic).
Any suggestions how we can solve this?
I solved this issue by building a pre- and post processor for the content.
In the pre-processor I replace text fragments with other text. For example the & and &AMP; will be replaced by a normal &. While preprocessing I store each replacement details in an replacement object, that will be added to an ordered list. A replacement object contains the original text and the difference in length (& is 4 characters longer than a single &).
After annotating with RUTA(and other annotators) I correct all the found annotation values (text) to the original value and I fix the position information (begin and end) of the annotations, so that they match with the original content. I use the list with replacement details for this process.

Docvariable with empty string value

In word, I'm using docvariables to manage pluralization.
A VBA macro is changing the value of several docvariables to pluralize / singularize them.
But sometimes I want to use a Docvariable only for enable/disable a 's' suffix.
Problem: I cannot set it to empty string, because it deletes the docvariable.
The field displays an error in word.
So I'm searching a way to achieve this, it could be :
A way to keep a Docvariable existing, with empty string or equivalent value
A field formula which make this job if the variable doesn't exist
Any other workaround would be appreciated.
Thank you
A Document Variable (used in DocVariable field codes) cannot exist if it has no content.
A possibility would be to also store the space in this DocVariable so that it display s[space] or just [space].
Otherwise you may need to write this information to a Bookmark (possibly using a Set field) and display the content using a Ref field.

zip code + 4 mail merge treated like an arithmetic expression

I'm trying to do a simple mail merge in Word 2010 but when I insert an excel field that's supposed to represent a zip code from Connecticut (ie. 06880) I am having 2 problems:
the leading zero gets suppressed such as 06880 becoming 6880 instead. I know that I can at least toggle field code to make it so it works as {MERGEFIELD ZipCode # 00000} and that at least works.
but here's the real problem I can't seem to figure out:
A zip+4 field such as 06470-5530 gets treated like an arithmetic expression. 6470 - 5530 = 940 so by using above formula instead it becomes 00940 which is wrong.
Perhaps is there something in my excel spreadsheet or an option in Word that I need to set to make this properly work? Please advise, thanks.
See macropod's post in this conversation
As long as the ZIP codes are reaching Word (with or without "-" signs in the 5+4 format ZIPs, his field code should sort things out. However, if you are mixing text and numeric formats in your Excel column, there is a danger that the OLE DB provider or ODBC driver - if that is what you are using to get the data - will treat the column as numeric and return all the text values as 0.
Yes, Word sometimes treats text strings as numeric expressions as you have noticed. It will do that when you try to apply a numeric format, or when you try to do a calculation in an { = } field, when you sum table cell contents in an { = } field, or when Word decides to do a numeric comparison in (say) an { IF } field - in the latter case you can get Word to treat the expression as a string by surrounding the comparands by double-quotes.
in Excel, to force the string data type when entering data that looks like a number, a date, a fraction etc. but is not numeric (zip, phone number, etc.) simply type an apostrophe before the data.
=06470 will be interpreted as a the number 6470 but ='06470 will be the string "06470"
The simplest fix I've found is to save the Excel file as CSV. Word takes it all at face value then.

Way to preserve formatting for lists when copy / pasting from table cell?

My Word interop application needs to get content out of a cell of a table in a word document. The problem is, that the formatting for some items seems broken. For example the last item of a list does not have the list style applyied. Headings are only normal text etc.
The same happens if you create a table, create a list in the table and try to copy / paste the list to somewhere else.
Has anyone else had this problem and maybe found a solution? Is there any way to trick word into giving the correct formatting?
Thanks in advance
Example code
Range range = cell.range;
range.MoveEnd(WdUnits.wdCharacter, -1);
...
range.FormattedText.copy()
The range includes the end-of-cell marker which should not be exported. I just noticed, when not altering the range, list are correctly formatted but the whole cell is exported as a table, which is bad because i want to import the content into another document (where this would nest tables infinitly)
Word2010 v14.06.6112.5000

How can I identify an OpenXml Paragraph as one I programmatically inserted?

I am programmatically adding an OpenXML paragraph to a Word Document and I need to be able to identify that paragraph as mine later on. Any ideas on how to do this? I have tried inserting an XML comment and extended attributes but when you save the document in word it removes all unknown xml. It doesn't matter if it is an attribute in the paragraph or the run, or an element before the paragraph, just some way I can identify it later on. Also, I do not want this identifier visible in the word document.
Examples of what I could use:
<paragraph id="myParagraph"></paragraph>
<otherelement>myparagraph</otherelement>
<paragraph></paragraph>
Any help would be AWESOME because my head it hurting from the brick wall I have been running into.
Thanks!
Give the paragraph a w:rsidR attribute and assign a unique value to it; if there is no value present when word saves the document it will randomly assign it's own 8-digit hexadecimal value anyway. (The value is not limited to 8 digits or hexadecimal characters. Word will not modify existing RSIDs.)
That being said -- make sure to keep RSID values unique and do NOT modify existing RSID attributes -- they are the unique ID for that paragraph, and if the document splits into multiple versions and a user tries to merge them back together those RSIDs are used to determine what paragraphs have changed.
(Also note that runs have RSIDs as well.)
If the user modifies the paragraph, the RSID of that paragraph may change.
The alternate option is to use Custom XML: http://msdn.microsoft.com/en-us/library/bb608618.aspx
Use stylename in paragraph properties.
or try this one
http://msdn.microsoft.com/en-us/library/office/hh674468.aspx
Hope this helps.