Saturday, 24 August 2013

Word Openxml: how to get a text box the right size

Word Openxml: how to get a text box the right size

I'm using PHP to generate docx documents from a database. The generated
document contains column charts which have labels attached (i.e. user
shapes containing textboxes). In an attempt to get the textboxes to
accommodate and display all of the text (i.e. it shouldn't be necessary
for the user to resize a textbox to see all the text) my code calculates
how many characters will fit into 3cm, adds linefeeds to the string as
required and tells me how many lines of text are needed. I have:
<a:xfrm xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:off x="1638276" y="1676399"/>
<a:ext cx="1257325" cy="'.(252000 * $labelLeftLines).'"/>
</a:xfrm>
which I believe should give me a text box around 3.5cm wide (extra .5 for
the internal padding) and a height of .7cm multiplied by whatever is the
value of $labelLeftLines. However, the text box always turns up as 3.cm
wide by .86cm high, which only ever displays one line of text. If I add in
'autofit':
<a:bodyPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
vertOverflow="clip" wrap="square" rtlCol="0">
<a:spAutoFit/>
</a:bodyPr>
the generated file looks just the same, though, when I right click on the
textbox to inspect the properties, 'autofit' is indeed applied. I have to
uncheck it and recheck it to make it affect the textbox. Any openXML gurus
out there?

No comments:

Post a Comment