2017-08-17 126 views

回答

3

邊框的默認寬度爲0,邊框不可見。爲了使邊框,設置的值大於0

如果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); 
} 
+0

我試過它沒有工作,我弄清楚如何tho。 – user629283

+0

我在我的文章中添加了工作代碼。 –

+0

哦,我設法讓它現在工作 – user629283

0

我設法通過設定每行邊界可見度,虛假拿到下來;

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; 

不看不錯,但如果任何人有一個更好的解決方案也發佈在了

+0

我的示例代碼工作時沒有設置可見性 - 它使用默認值正常工作。 'p.AddFormattedText(「頂部標題行」)的目的是什麼;'? –

+0

@PDFsharpNovice我試過,但它沒有爲我工作 – user629283

+0

@PDFsharpNovice當我試過你的方式,它刪除所有的邊界線,包括周圍的表。 p.addformattedText部分 - 這是一個快速複製和粘貼,但我會讓這部分大膽。 – user629283

相關問題