简体   繁体   English

MigraDoc - 表格边框但没有单元格/行/列边框

[英]MigraDoc - Table Border but no Cell/Row/Column Borders

I am struggling to implement what seems should be something straight forward, but having not much luck.我正在努力实施似乎应该是直截了当的事情,但运气不佳。 I need a MigraDoc table to render with just the Table border, excluding all cells in between:我需要一个 MigraDoc 表格来渲染表格边框,不包括中间的所有单元格:

在此处输入图片说明

I have followed the remarks on this post:我已经关注了这篇文章的评论:

How do you add a border around a table in MigraDoc? 如何在 MigraDoc 中为表格添加边框?

Useful information but I havent been able to implement a full fix from it?有用的信息,但我还没有能够从中实施完整的修复? I have the following code run just before the table is added to the section:在将表添加到该部分之前,我运行了以下代码:

        table.Borders.Visible = true;
        for (int i = 0; i < table.Rows.Count - 2; i++)
        {
            table.Rows[i].Borders.Bottom.Visible = false;
        }

Which at first seemed like it did the job... until I come across a table that follows onto the next page... The bottom row border is obviously only rendered for the very bottom row and does not account for PageBreaks mid-table.起初似乎它完成了这项工作......直到我遇到一个跟随下一页的表格......底行边框显然只为最底行呈现并且不考虑PageBreaks中间表。

Surely there must be a better way of doing this?当然必须有更好的方法来做到这一点?

EDIT: I appreciate this is somewhat of an old question, but just incase anyone ends up here looking for an answer...编辑:我很欣赏这是一个老问题,但以防万一有人最终在这里寻找答案......

Try using the SetEdge option.尝试使用SetEdge选项。 There's two ways you could do it, depending on whether you know how many table rows or columns you're going to have (static content), or you don't know yet (dynamic content).有两种方法可以做到这一点,这取决于您是否知道将有多少表格行或列(静态内容),或者您还不知道(动态内容)。

Option 1: Static table content选项 1:静态表格内容

Set your table up first, so all the columns, cells and rows exist, then add an edge border to your table with首先设置你的表格,这样所有的列、单元格和行都存在,然后用

table.SetEdge(a, b, x, y, Edge.Box, BorderStyle.Single, 1, Colors.Black);

The first four numbers a, b, x, y indicate which of the table cells you want to add a borders to, the first two numbers are the top left column then row (in your case to border the whole table, this should be 0, 0 ) and the second two numbers are the bottom right corner column then row (as per your example this is 3, 4 , assuming the heading is a heading row).前四个数字a, b, x, y表示您要为其添加边框的表格单元格,前两个数字是左上角的列然后是行(在您的情况下为整个表格边框,这应该是0, 0 ) 和第二个数字是右下角的列然后是行(根据您的示例,这是3, 4 ,假设标题是标题行)。

After Edge.Box , the options are border style, border width, border color .Edge.Box之后,选项是border style, border width, border color

You can then add any extra individual borders per cell or row after as normal, so to add a border at the bottom of your header row as per your example...然后,您可以像往常一样为每个单元格或行添加任何额外的单独边框,以便按照您的示例在标题行的底部添加边框...

headerRow.Borders.Bottom.Width = 0.2;
headerRow.Borders.Bottom.Color = Colors.Black;

Option 2: Dynamic table content选项 2:动态表格内容

If you don't know how many rows or columns are in your table becuase the content is dynamic, the first four numbers in SetEdge could be set with this.table.Columns.Count and this.table.Rows.Count - for example :如果您不知道表格中有多少行或列,因为内容是动态的,可以使用this.table.Columns.Countthis.table.Rows.Count设置this.table.Columns.Count的前四个数字 - 例如:

table.SetEdge(0, 0, this.table.Columns.Count, this.table.Rows.Count, Edge.Box, BorderStyle.Single, 1, Colors.Black);

References参考文献

For more info, see this post: https://forum.pdfsharp.net/viewtopic.php?f=2&t=3598有关更多信息,请参阅此帖子: https : //forum.pdfsharp.net/viewtopic.php?f=2&t=3598

And it's also here in the MigraDoc Example (search for SetEdge): http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx它也在 MigraDoc 示例中(搜索 SetEdge): http ://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM