Categories > OpenTBS with DOCX >

Is there a way to manipulate "shapes" in Word documents?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Paul
Date: 2013-05-05
Time: 13:50

Is there a way to manipulate "shapes" in Word documents?

Hi all,

I have a need to have a diagram in a Word document made of about 10 different "shapes" - Word -> Insert -> Square, Circle, etc.  Programmatically I need to alter the colour of each shape depending on data - is there a way to do this?  I've had a bit of a play but haven't been able to work out if this would be possible.  Looking at the document.xml I can see huge long tags for each shape but have no idea how to change the colour.  Has anyone else done anything like this?

Thanks,
Paul.
By: Skrol29
Date: 2013-05-05
Time: 16:39

Re: Is there a way to manipulate "shapes" in Word documents?

Hi,

Here is a synopsis of the XML in Ms Word for a shape with red border:
<mc:AlternateContent>
  <mc:Choice Requires="wps">
  <w:drawing>
    <wp:anchor ... >
    <wp:simplePos x="0" y="0"/>
    ...
    <wp:docPr id="1" name="Émoticône 1" descr="my description" title="my title"/>
    <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
      <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
      <wps:wsp>
        ...
        <a:ln>
          <a:solidFill>
          <a:srgbClr val="FF0000"/>
          </a:solidFill>
        </a:ln>

We can see that the color is defined by the element  <a:srgbClr val="FF0000"/>.
But in fact, this element is added by Ms Word only if you customize the border color. Otherwise the border color is defined from the style appled to the shape and there is no <a:srgbClr> element.

So, the solution is to first custmize the border color of the shape and add a TBS field in the description of the shape.
The TBS must have parameter "att" in order to move itself to the target attribute in the target element.

Example:
[onshow.my_color;att=+a:srgbClr#val]