有沒有辦法在表格周圍添加邊框並隱藏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. 如何在TableLayout周圍添加邊框?
- 3. 如何在QWidget周圍添加邊框?
- 4. 如何在邊框周圍添加另一個邊框?
- 5. 如何在網格行周圍添加透明邊框?
- 6. 如何在標題邊框周圍添加空格?
- 7. QLabel在文字周圍添加「邊框」
- 8. 如何在R中的圖例周圍添加邊框?
- 9. 錶行邊框 - Migradoc
- 10. UIBezierPath:如何在帶圓角的視圖周圍添加邊框?
- 11. 如何在按鈕的文字周圍添加邊框?
- 12. 如何在圖像周圍添加圓角邊框?
- 13. 如何在tr標籤周圍添加邊框?
- 14. 如何在treeViewItem周圍添加邊框,包括箭頭WPF/C#
- 15. MigraDoc PDFSharp添加頁面邊框
- 16. 在HTML中的表格中的特定列周圍的邊框
- 17. 在C#中的TextBox周圍添加彈出邊框動畫wpf
- 18. 如何在添加邊距後刪除工具欄周圍的額外邊框?
- 19. 如何在VariableSizedWrapGrid周圍放置邊框?
- 20. CSS3邊框/網格周圍的空隙
- 21. 在jasperreports中添加表格邊框
- 22. 如何在狀態周圍添加邊框在宣傳單張中地圖
- 23. 如何擺脫JavaFX中拆分窗格周圍的邊框?
- 24. 添加表格邊框
- 25. 在TreeViewItem的所有子節點周圍添加邊框
- 26. 在旋轉木馬的圖像部分周圍添加邊框
- 27. 在固定寬度的SVG周圍添加邊框?
- 28. 表格周圍的邊框,但不是單元格
- 29. 無法獲取表格邊框/單元格周圍的線條
- 30. HTML表格:刪除空白單元格周圍的邊框
你嘗試過什麼了嗎? – PaulF
我試過table.Borders.Visible = true;並且對於每一行我都嘗試將其設置爲可見的假,試圖將頂部顏色更改爲空。 – user629283