You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Odoo的Qweb报表中每页显示表头并解决内容重叠问题

解决QWeb报表多页场景下长文本与表头重叠的问题

我来帮你搞定这个多页报表里长文本和表头重叠的问题!这个问题通常出现在分页时,长文本没有自动换行,加上表头没有固定定位,导致内容和表头叠在一起。咱们从三个方面调整代码就能解决:

  • 给表头设置固定定位,让它在分页时始终停在页面顶部,不会被内容覆盖
  • 给长文本所在单元格添加自动换行样式,避免内容溢出
  • 修正总计行的列合并问题,避免表格结构错乱

以下是修改后的完整代码:

<table class="table table-bordered" width="100%" style="border-collapse: collapse;">
    <thead style="position: sticky; top: 0; background-color: #fff; page-break-inside: avoid;">
        <tr>
            <td class="text-left">Code</td>
            <td class="text-left">Description</td>
            <td class="text-left">U/M</td>
            <td class="text-right">QTY</td>
            <td class="text-right">RATE</td>
            <td class="text-right">TAX</td>
            <td class="text-right">TOTAL</td>
        </tr>
    </thead>
    <tbody class="invoice_tbody">
        <tr t-foreach="o.invoice_line_ids" t-as="l" style="page-break-inside: avoid;">
            <td><span t-field="l.product_id.default_code"/></td>
            <td style="word-wrap: break-word; white-space: normal;"><span t-field="l.name"/></td>
            <td><span t-field="l.uom_id.name"/></td>
            <td class="text-right"><span t-field="l.quantity"/></td>
            <td class="text-right"><span t-field="l.price_unit"/></td>
            <td class="text-right"><span t-field="l.price_tax"/></td>
            <td class="text-right"><span t-field="l.price_total"/></td>
        </tr>
        <tr style="page-break-inside: avoid;">
            <td class="text-left" colspan="4">
                <b>GRAND TOTAL AED :</b>
            </td>
            <td class="text-right">
                <b><span t-field="o.amount_untaxed"/></b>
            </td>
            <td class="text-right">
                <b><span t-field="o.amount_tax"/></b>
            </td>
            <td class="text-right">
                <b><span t-field="o.amount_total"/></b>
            </td>
        </tr>
    </tbody>
</table>

关键修改点说明:

  1. 表头固定:给<thead>添加position: sticky; top: 0; background-color: #fff,确保分页时表头不会被内容覆盖,背景色设置为白色是为了遮住后面的内容。
  2. 长文本换行:给Description列的<td>添加word-wrap: break-word; white-space: normal,强制长文本自动换行,避免内容溢出到表头区域。
  3. 表格结构修正:原代码里总计行的colspan和列数不匹配,我调整了总计行的colspan,同时直接使用Odoo自带的合计字段(amount_untaxed、amount_tax、amount_total),不用自己循环计算,更简洁可靠。
  4. 分页优化:给每个数据行和总计行都添加page-break-inside: avoid,避免一行内容被拆分成两页。

这样调整后,多页报表里的长文本会自动换行,表头也会固定在顶部,就不会出现重叠的问题啦!

内容的提问来源于stack exchange,提问作者Jack Sparrow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:52:41