有没有办法在表格周围添加边框并隐藏 MigraDoc 中的单元格边框?
最佳答案
边框的默认宽度为 0,边框不可见。要启用边框,请设置一个大于 0 的值。
如果 table
是您的 Table 对象,您可以编写 table.Borders.Width = 0.5;
您可以为表格和每个单元格设置边框。单元格从表格、列、行继承边框属性,除非它们在较低的阶段被覆盖。
还要检查 Table
类的 SetEdge
方法。
此处讨论的示例代码:
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);
}
关于c# - 如何在 MigraDoc 中的表格周围添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45737856/