reportlab: setting colspan for td in rml

我怕爱的太早我们不能终老 提交于 2019-12-01 05:56:22

The normal ReportLab way to do this would be to instead use Platypus and the Table flowable. When you set the style of the Table, you can specify a 'SPAN' command that will bundle any rectangular area of cells into one. You'll find more information on this in the ReportLab User Guide, chapter 7, page 81.

If you must use RML, I'm inclined to think that colspan is simply not available. It's at least not in the ReportLab RML reference document. Instead I think you are supposed to use blockSpan elements. There's no example given, but you'll find it in the RML manual.

Gordon's suggestion of the blockSpan element worked for me. Here's an example of how to use it:

<?xml version="1.0"?>
<document filename="test.pdf">
  <template pageSize="(612,792)" title="Test" author="Don Kirkby">
    <pageTemplate id="first">
      <frame id="first" x1="10.0" y1="10.0" width="592" height="772"/>
    </pageTemplate>
  </template>
  <stylesheet>
    <blockTableStyle id="main">
      <blockSpan start="0,1" stop="1,1"/>
    </blockTableStyle>
  </stylesheet>
  <images/>
  <story>
    <blockTable colWidths="100.0,287.5,187.5" style="main">
      <tr>
        <td><para>Cell 0,0</para></td>
        <td><para>Cell 1,0</para></td>
        <td><para>Cell 2,0</para></td>
      </tr>
      <tr>
        <td><para>Cell 0,1 will flow into its neighbour</para></td>
        <td><para>Cell 1,1 will not appear, but must be present</para></td>
        <td><para>Cell 2,1</para></td>
      </tr>
      <tr>
        <td><para>Cell 0,2</para></td>
        <td><para>Cell 1,2</para></td>
        <td><para>Cell 2,2</para></td>
      </tr>
    </blockTable>
  </story>
</document>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!