C# 如何在itextsharp pdf创建中设置单元格宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9208482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set the cell width in itextsharp pdf creation
提问by Fernando
How can I set cell width and height in itextsharp pdf cell ceration using c#. I just use
如何使用 c# 在 itextsharp pdf 单元格中设置单元格宽度和高度。我只是用
cell.width = 200f;
But it should display the error message.
但它应该显示错误消息。
width can not be set.
宽度不能设置。
What should I do?..
我该怎么办?..
采纳答案by Neha
http://indaravind.blogspot.in/2009/02/itextsharp-table-column-width.html
http://indaravind.blogspot.in/2009/02/itextsharp-table-column-width.html
VB:
VB:
Dim intTblWidth() As Integer = {12, 10, 26, 10}
C#:
C#:
int[] intTblWidth = { 12, 10, 26, 10 };
回答by JP Hellemons
You don't set the width of a cell.
您没有设置单元格的宽度。
you should set the width of the columns. And you can do that by applying them on the table object:
您应该设置列的宽度。您可以通过将它们应用于 table 对象来做到这一点:
float[] widths = new float[] { 1f, 2f };
table.SetWidths(widths);
The answer from Neha is to set the width of the table object
Neha的答案是设置表格对象的宽度
more reference material here: http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables
更多参考资料在这里:http: //www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables
回答by JumpingHyman
cell.width = 200f;you have to put capital W on width correct is cell.Width = 200f;
cell.width = 200f;你必须把大写 W 放在宽度上正确的是 cell.Width = 200f;
回答by vijay sekhar reddy
int count=Gridview1.Columns.Count
PdfPTable table = new PdfPTable(count);
float[] columnWidths = new float[count];
for (int v = 0; v < count; v++)
{
if (v == 0) {
columnWidths[v] = 10f;
}
else if (v == 2)
{
columnWidths[v] = 30f;
}
else if(v == 3)
{
columnWidths[v] = 15f;
}
else if(v == 4)
{
columnWidths[v] = 18f;
}
else if(v == 5|| v == 6|| v == 7)
{
columnWidths[v] = 22f;
}
else
{
columnWidths[v] = 20f;
}
}
table.SetWidths(columnWidths);

