如何使 html 字段(使用 CKeditor 编辑)的 table 边框可见?
How can I make the table borders of an html field (edited with CKeditor) visible?
我正在尝试打印使用 CKeditor 格式化的 html 字段的内容。为此,我将字段 note
更改为 html 字段,如下所示:
from openerp import models, fields
class CustomSaleOrder(models.Model):
_inherit = 'sale.order'
note = fields.Html(
string='Terms and conditions',
)
我还更改了报告以打印 html 代码:
<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
<xpath expr="//p[@t-field='o.note']" position="replace">
<p t-raw="o.note" />
</xpath>
</template>
我想在 CKeditor 中创建表格并使它们在报告中可见(带有边框)。似乎有一个 plugin of CKeditor 可以做到这一点,但我不知道它是否能正常工作或者是否可以安装它。
我还检查了如何在数据库中保存 html 字段以及如何使用 border="1"
属性保存表:
<table border="1" cellpadding="1" cellspacing="1" style="width:500px">
<tbody>
<tr>
<td>cell 1</td>
[...]
如果我将报告打印为 html,则表格是可见的,但如果我将报告打印为 pdf,则边框是不可见的。
有没有简单的方法可以实现?
嗯,我解决了问题:
首先我在报告中添加了一个class和一个自定义样式:
<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
<xpath expr="//p[@t-field='o.note']" position="replace">
<div class="ckeditor_field">
<p t-raw="o.note" />
</div>
</xpath>
</template>
<template id="custom_sale_order_style" inherit_id="report.layout">
<xpath expr="//style" position="after">
<style type="text/css">
.ckeditor_field table {
margin: 12px 0px 12px 0px;
}
.ckeditor_field table td {
border: 1px solid black;
vertical-align: middle;
padding: 8px 10px 8px 10px;
}
.ckeditor_field p {
line-height: 1;
}
</style>
</xpath>
</template>
而且我还添加了另一个 class 到具有相同或相似 CSS 的视图。我这样做是为了在保存字段时查看表格:
<record id="view_order_form_wtd" model="ir.ui.view">
<field name="name">sale.order.form.wtd</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="note" position="replace">
<field name="note" class="note_wtd" widget="html" />
</field>
</field>
</record>
我正在尝试打印使用 CKeditor 格式化的 html 字段的内容。为此,我将字段 note
更改为 html 字段,如下所示:
from openerp import models, fields
class CustomSaleOrder(models.Model):
_inherit = 'sale.order'
note = fields.Html(
string='Terms and conditions',
)
我还更改了报告以打印 html 代码:
<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
<xpath expr="//p[@t-field='o.note']" position="replace">
<p t-raw="o.note" />
</xpath>
</template>
我想在 CKeditor 中创建表格并使它们在报告中可见(带有边框)。似乎有一个 plugin of CKeditor 可以做到这一点,但我不知道它是否能正常工作或者是否可以安装它。
我还检查了如何在数据库中保存 html 字段以及如何使用 border="1"
属性保存表:
<table border="1" cellpadding="1" cellspacing="1" style="width:500px">
<tbody>
<tr>
<td>cell 1</td>
[...]
如果我将报告打印为 html,则表格是可见的,但如果我将报告打印为 pdf,则边框是不可见的。
有没有简单的方法可以实现?
嗯,我解决了问题:
首先我在报告中添加了一个class和一个自定义样式:
<template id="custom_sale_order" inherit_id="sale.report_saleorder_document">
<xpath expr="//p[@t-field='o.note']" position="replace">
<div class="ckeditor_field">
<p t-raw="o.note" />
</div>
</xpath>
</template>
<template id="custom_sale_order_style" inherit_id="report.layout">
<xpath expr="//style" position="after">
<style type="text/css">
.ckeditor_field table {
margin: 12px 0px 12px 0px;
}
.ckeditor_field table td {
border: 1px solid black;
vertical-align: middle;
padding: 8px 10px 8px 10px;
}
.ckeditor_field p {
line-height: 1;
}
</style>
</xpath>
</template>
而且我还添加了另一个 class 到具有相同或相似 CSS 的视图。我这样做是为了在保存字段时查看表格:
<record id="view_order_form_wtd" model="ir.ui.view">
<field name="name">sale.order.form.wtd</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="note" position="replace">
<field name="note" class="note_wtd" widget="html" />
</field>
</field>
</record>