gpt4 book ai didi

c# - ITextSharp : Set table cell border color

转载 作者:IT王子 更新时间:2023-10-29 04:42:51 25 4
gpt4 key购买 nike

如何设置表格单元格的边框颜色。这是我的代码:

// 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);

如您所见,我以两种不同的方式设置颜色,但两种方式均无效。呈现表格时,边框始终为黑色。我该如何解决这个问题。

最佳答案

当您设置个别 单元格边框属性时,您需要单独设置所有 边框颜色和宽度,或者显式设置UseVariableBorders属性为 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);

关于c# - ITextSharp : Set table cell border color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9417054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com