首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ITextSharp:设置表单元格边框颜色

ITextSharp:设置表单元格边框颜色
EN

Stack Overflow用户
提问于 2012-02-24 00:28:14
回答 1查看 67K关注 0票数 19

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

代码语言:javascript
复制
// 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);

如你所见,我用两种不同的方法设置颜色,两种方法都不起作用。在渲染表格时,边框始终为黑色。我怎么才能解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-24 03:14:09

在设置单个单元格边框属性时,您需要分别设置all边框颜色和宽度,或者将UseVariableBorders属性显式设置为true。尝试这个例子来理解我的意思:

代码语言:javascript
复制
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);
票数 31
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9417054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档