Search code examples
ms-wordopenxmlopenxml-sdk

Manipulate status of links in Word document with OpenXML SDK


I have a Word-Document with some links to cells in Excel-files. In Word, I can get a context menu, that leads to a window with all the links of the document. There, I can see and manipulate properties of the links.

Amongst others, there is the part "Updatemethod for chosen link" (words may differ, I translated it from the German version), I have two radio-boxes with "automatic" / "manual". And a Checkbox "locked".

I want to modify (especially the locked-checkbox) these properties with OpenXML, but I did not find the place, where in the model this information is stored. I printed the OuterXML for a link with locked checked and for a link with locked unchecked, but did not find any differences in the parameter field (\a \f 5 \h * MERGEFORMAT - for both!)

Anyone knows, how I can modify this with OpenXML SDK?

Thanks in advance,
Frank


Solution

  • Word has different ways to represent the LINK in Office Open XML depending partly on the format of the link (e.g. whether you Paste Link to an object or to plain text).

    For example, if you paste a link to a "Microsoft Excel Worksheet Object", although Word displays a LINK field in the document, the XML does not actually record the field code using either the simple or more complex encoding for field codes. It actually encodes the object in a <w:object> element that records information about a "shape", with the shape type in <v:shapetype>, the shape itself in <v:shape>, and information about the OLE link in <o:OLEObject>

    In that case, Automatic link updating is recorded using

    <o:OLEObject UpdateMode='Always'> for automatic links

    and

    <o:OLEObject UpdateMode='OnCall'> for manual links.

    Whether or not the link is Locked is recorded in

    <o:OLEObject><o:LockedField></o:LockedField<o:OLEObject>
    

    (either as "false" or "" AFAICS).

    Word reconstructs the LINK field code from the w:object information when it displays the document.

    However, if you paste the link as text, the XML Word records will contain a complex field code construction, starting with a <w:fldChar w:fldCharType='begin' /> element.

    In that case, the fact that the link is locked is indicated by a value of '1" in the w:fldLock attribute, and probably the absence of that attribute if it is not locked. e.g.

    <w:fldChar w:fldCharType='begin' w:fldLock='1' />

    In either case, an automatic link is indicated by the presence of the \a switch in the field code (reconstructed in the case of the first example). If there is no \a switch, it's not an automatic link.

    That may not cover all the possible cases but should give you some clues about where to look in the XML.