reportlab: setting colspan for td in rml

谁都会走 提交于 2019-12-04 01:27:01

问题


I can't find any option, that would allow to set colspan for td element in rml. Is that somehow possible?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/5002944/reportlab-setting-colspan-for-td-in-rml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!