如何在 MigraDoc 中为表格添加边框?

use*_*283 3 c# migradoc

有没有办法在表格周围添加边框并在 MigraDoc 中隐藏单元格边框?

Je *_*not 5

边框的默认宽度为 0,边框不可见。要启用边框,请设置一个大于 0 的值。

如果table是你的 Table 对象,你可以写table.Borders.Width = 0.5;

您可以为表格和每个单元格设置边框。单元格从表、列、行继承边框属性,除非它们在较低阶段被覆盖。

还要检查类的SetEdge方法Table

此处讨论的示例代码:http :
//www.pdfsharp.net/wiki/Invoice-sample.ashx

我的测试代码:

private static void TabelWithBorderTest()
{
    var document = new Document();

    // Add a section to the document.
    var section = document.AddSection();

    Table table = section.AddTable();
    table.Borders.Width = 0.25;
    table.Rows.LeftIndent = 0;

    // Before you can add a row, you must define the columns
    Column column = table.AddColumn("7cm");
    column.Format.Alignment = ParagraphAlignment.Left;

    Row row = table.AddRow();
    row.Cells[0].AddParagraph("Text in table");

    // Create a renderer for the MigraDoc document.
    var pdfRenderer = new PdfDocumentRenderer(false) { Document = document };

    // Associate the MigraDoc document with a renderer.

    // Layout and render document to PDF.
    pdfRenderer.RenderDocument();

    // Save the document...
    const string filename = "TableTest.pdf";
    pdfRenderer.PdfDocument.Save(filename);
    // ...and start a viewer.
    Process.Start(filename);
}
Run Code Online (Sandbox Code Playgroud)