有沒有辦法在表格周圍添加邊框並隱藏MigraDoc中的單元格邊框?如何在MigraDoc中的表格周圍添加邊框?
回答
邊框的默認寬度爲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);
}
我設法通過設定每行邊界可見度,虛假拿到下來;
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;
不看不錯,但如果任何人有一個更好的解決方案也發佈在了
我的示例代碼工作時沒有設置可見性 - 它使用默認值正常工作。 'p.AddFormattedText(「頂部標題行」)的目的是什麼;'? –
@PDFsharpNovice我試過,但它沒有爲我工作 – user629283
@PDFsharpNovice當我試過你的方式,它刪除所有的邊界線,包括周圍的表。 p.addformattedText部分 - 這是一個快速複製和粘貼,但我會讓這部分大膽。 – user629283
- 1. Silverlight:在網格周圍添加邊框
- 2. 如何在QWidget周圍添加邊框?
- 3. 如何在邊框周圍添加另一個邊框?
- 4. QLabel在文字周圍添加「邊框」
- 5. 如何在R中的圖例周圍添加邊框?
- 6. 錶行邊框 - Migradoc
- 7. UIBezierPath:如何在帶圓角的視圖周圍添加邊框?
- 8. 如何在圖像周圍添加圓角邊框?
- 9. 如何在treeViewItem周圍添加邊框,包括箭頭WPF/C#
- 10. 如何在tr標籤周圍添加邊框?
- 11. 如何在添加邊距後刪除工具欄周圍的額外邊框?
- 12. CSS3邊框/網格周圍的空隙
- 13. 在jasperreports中添加表格邊框
- 14. 如何在狀態周圍添加邊框在宣傳單張中地圖
- 15. 在TreeViewItem的所有子節點周圍添加邊框
- 16. 圖像周圍的邊框
- 17. Android - ListFragment周圍的邊框?
- 18. 選擇性地在圖像視圖周圍添加邊框
- 19. 如何在網頁正文的所有元素周圍添加邊框?
- 20. 在MigraDoc中,我如何用相同的邊框包圍一些文本和表格?
- 21. 如何在Chrome中爲表格單元添加透明邊框?
- 22. 如何在表格中添加行邊框
- 23. 如何使用CSS在圖像周圍添加非矩形邊框?
- 24. CSS - 如何在圓形圖像周圍添加圓形邊框/輪廓?
- 25. WPF彈出窗口:如何在彈出窗口周圍添加邊框?
- 26. 向表格單元格添加邊框
- 27. 表格周圍的不同行邊框顏色
- 28. PHP:如何周圍添加空格「 - 」用正則表達式
- 29. 如何在HelloGallery中更改圖像周圍的邊框厚度
- 30. 如何在ItemsControl中的每個元素周圍繪製邊框?
你嘗試過什麼了嗎? – PaulF
我試過table.Borders.Visible = true;並且對於每一行我都嘗試將其設置爲可見的假,試圖將頂部顏色更改爲空。 – user629283