不好意思,各位前輩
類似的問題就是我使用itextsharp,想針對TABLE對每一格控制是否需要框線(如,上/下/左/右框線)
請問有什麼語法可以參考嗎?
參考這篇 Itextsharp PDFPTable how to make a border around entire table
使用DisableBorderSide
方法, 隱藏某一邊.
實作會這樣, 第一個Cell只留右邊、第二個Cell只留下邊
protected void Page_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream("Example2.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.Add(new Paragraph("Hello World"));
doc.Add(GetTable2());
doc.Close();
}
private PdfPTable GetTable2()
{
PdfPTable table = new PdfPTable(1);
PdfPCell cell1 = new PdfPCell(new Phrase("Some Text1"));
cell1.DisableBorderSide(Rectangle.TOP_BORDER);
cell1.DisableBorderSide(Rectangle.BOTTOM_BORDER);
cell1.DisableBorderSide(Rectangle.LEFT_BORDER);
table.AddCell(cell1);
PdfPCell cell2 = new PdfPCell(new Phrase("Some Text2"));
cell2.DisableBorderSide(Rectangle.TOP_BORDER);
cell2.DisableBorderSide(Rectangle.RIGHT_BORDER);
cell2.DisableBorderSide(Rectangle.LEFT_BORDER);
table.AddCell(cell2);
return table;
}