drmacro / wordinator

Generate high-quality DOCX files using a simplified XML format (simple word processing XML).
Apache License 2.0
38 stars 8 forks source link

Autofit content for tables #121

Open gkholman opened 1 year ago

gkholman commented 1 year ago

Reviewing the documentation for the table element:

<optional>
  <attribute name="layout" a:defaultValue="fixed">
    <a:documentation>
      <p>Controls whether the table layout is fixed or automatic. Automatic layout allows 
      Word to resize columns based on cell content. Default is "fixed".</p>
    </a:documentation>
    <choice>
      <value>auto</value>
      <value>fixed</value>
    </choice>
  </attribute>
</optional>

I find that the test file in autofit-20230424.zip is producing undesirable results:

image ... even with layout="auto":

<wp:body>
  <wp:p style="Ref List Back Heading">
    <wp:bookmarkStart id="sec_bibl" name="sec_bibl"/>
    <wp:run>Bibliography</wp:run>
    <wp:bookmarkEnd id="sec_bibl"/>
  </wp:p>
  <wp:table layout="auto" frame="none" colsep="0" rowsep="0">
    <wp:tbody>
            <wp:tr>
              <wp:td colspan="1" rowspan="1" valign="top" align="justify">
                <wp:p style="Body Text">
                  <wp:run>[1]</wp:run>
                </wp:p>
              </wp:td>
              <wp:td colspan="1" rowspan="1" valign="top" align="justify"/>
              <wp:td colspan="1" rowspan="1" valign="top" align="justify">
                <wp:p style="Body Text">
                  <wp:run>ISO 1035-3</wp:run>
                  <wp:run>, </wp:run>
                  <wp:run style="Standard Title">Hot-rolled steel bars — Part 3: Dimensions of flat bars</wp:run>
                </wp:p>
              </wp:td>
            </wp:tr>
    </wp:tbody>
  </wp:table>
</wp:body>
gkholman commented 1 year ago

On a lark I hacked out the colspan="1" and rowspan="1" and the automatic fitting to content worked just fine.

I've omitted preserving these attributes when their value is "1" and my results are as I want.

You can close this ticket on my account, but I've left it open since it seems like a bug somewhere in the chain.