有没有办法在桌子周围添加边框并在MigraDoc中隐藏单元格边框?
答案 0 :(得分:4)
边框的默认宽度为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);
}
答案 1 :(得分:0)
我设法通过将每行边框可见性设置为false来解决此问题;
var document = new Document();
var page = document.AddSection();
Table table = page.AddTable();
table.Borders.Visible = true;
Column col = table.AddColumn("3cm");
col = table.AddColumn("10cm");
col = table.AddColumn("3cm");
col.Format.Alignment = ParagraphAlignment.Left;
Row row = table.AddRow();
Paragraph p = row.Cells[0].AddParagraph();
p.AddFormattedText("Top header row");
row.Cells[0].MergeRight = 2;
// then set it in visible as false like this, you can do top, left and right as well
row.Cells[0].Borders.Bottom.Visible = false;
看起来不是很好但是如果有人有更好的解决方案,请将其发布