web-dev-qa-db-ja.com

ITextSharp:テーブルセルの境界線の色を設定

テーブルセルの境界線の色を設定するにはどうすればよいですか。ここに私が持っているコードがあります:

// create and define table
var table = new PdfPTable(8);
table.HorizontalAlignment = Element.ALIGN_CENTER;

//table.HeaderRows = 1;

// the cell object
PdfPCell cell;
var f = FontFactory.GetFont("Tahoma", 11, Font.BOLD);

cell = new PdfPCell(new Phrase("Source Review", f));
cell.BorderColorLeft = new BaseColor(255, 255, 255);
cell.BorderColorRight = new iTextSharp.text.BaseColor(255, 255, 255);
table.AddCell(cell);

あなたが見ることができるように、私は2つの異なる方法で色を設定していますが、どちらの方法も機能していません。テーブルがレンダリングされるとき、境界線は常に黒です。どうすれば修正できますか。

19
Luke101

individualセル境界線プロパティを設定する場合、all境界線の色と幅を個別に設定するか、 seVariableBorders プロパティをtrueに明示的に設定します。この例を試して、意味を確認してください。

PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell(new Phrase("test 1"));
cell.UseVariableBorders = true;
cell.BorderColorLeft = BaseColor.BLUE;
cell.BorderColorRight = BaseColor.ORANGE;
table.AddCell(cell);

cell = new PdfPCell(new Phrase("test 2"));
cell.BorderColorLeft = BaseColor.RED;
cell.BorderColorRight = BaseColor.GREEN;
cell.BorderColorTop = BaseColor.PINK;
cell.BorderColorBottom = BaseColor.YELLOW;
cell.BorderWidthLeft = 1f;
cell.BorderWidthRight = 1f;
cell.BorderWidthTop = 1f;
cell.BorderWidthBottom = 1f;
table.AddCell(cell);

cell = new PdfPCell(new Phrase("test 3"));
cell.BorderColor = BaseColor.GREEN;
table.AddCell(cell);
30
kuujinbo