如何使用c#在itextsharp pdf cell ceration中设置单元格宽度和高度。我只是用
cell.width = 200f;
但它应该显示错误消息。
宽度无法设定。
我该怎么办?
答案 0 :(得分:36)
您没有设置单元格的宽度。
您应该设置列的宽度。你可以通过在表对象上应用它们来做到这一点:
float[] widths = new float[] { 1f, 2f };
table.SetWidths(widths);
Neha的答案是设置表格对象的宽度
此处有更多参考资料:http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables
答案 1 :(得分:12)
http://indaravind.blogspot.in/2009/02/itextsharp-table-column-width.html
VB:
Dim intTblWidth() As Integer = {12, 10, 26, 10}
C#:
int[] intTblWidth = { 12, 10, 26, 10 };
答案 2 :(得分:1)
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);
答案 3 :(得分:0)
#region Name..!!
PdfPTable tblName = new PdfPTable(3);
tblName.WidthPercentage = 98f;
float[] colWidthsaccing4 = { 100, 500, 700 };
tblName.SetWidths(colWidthsaccing4);
PdfPCell celladdingo4;
celladdingo4 = new PdfPCell(new Phrase(" ", Smallspace));
celladdingo4.HorizontalAlignment = 1;
celladdingo4.BorderWidth = 0;
celladdingo4.Colspan = 2;
tblHeader6.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase("1.", TableFontmini_ARBold8Nor));
celladdingo4.HorizontalAlignment = 1;
celladdingo4.PaddingBottom = 5f;
celladdingo4.BorderWidth = 0.5f;
tblName.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase(" Name :", TableFontmini_ARBold8Nor));
celladdingo4.HorizontalAlignment = 0;
celladdingo4.PaddingBottom = 5f;
celladdingo4.BorderWidth = 0.5f;
tblName.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase(" " +dt.Rows[0]["EmpName"].ToString(), TableFontmini_ARBold8Nor));
celladdingo4.HorizontalAlignment = 0;
celladdingo4.PaddingBottom = 5f;
celladdingo4.BorderWidth = 0.5f;
tblName.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase(" ", Smallspace));
celladdingo4.HorizontalAlignment = 1;
celladdingo4.BorderWidth = 0;
celladdingo4.Colspan = 2;
tblHeader6.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase(" ", Smallspace));
celladdingo4.HorizontalAlignment = 1;
celladdingo4.BorderWidth = 0;
celladdingo4.Colspan = 2;
tblHeader6.AddCell(celladdingo4);
celladdingo4 = new PdfPCell(new Phrase(" ", Smallspace));
celladdingo4.HorizontalAlignment = 1;
celladdingo4.BorderWidth = 0;
celladdingo4.Colspan = 2;
tblHeader6.AddCell(celladdingo4);
doc.Add(tblName);
#endregion
答案 4 :(得分:-2)
cell.width = 200f;
你必须将宽度正确的大写W设为cell.Width = 200f;