以下代码为我提供了iText中的表格。
但是,我还想在表的右侧添加另外两列;一个显示另一个' ='标志,(基本上与现有表格的第二列完全相同),然后在右侧,我想添加另一列显示' a' (与现有表格的第1列相同)。
所以我真的想拿现有的表,然后按顺序将第2列和第1列添加到它的末尾,这样我就完成了一个包含5列的表。我需要为此生成嵌套表吗?任何帮助将不胜感激。
PdfPTable table0 = new PdfPTable(3);
float[] widths = new float[] { 7f, 0.5f, 4f };
table0.SetWidths(widths);
PdfPCell cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("b"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("c"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
document.Add(table0);
答案 0 :(得分:0)
要“将第2列和第1列添加到”表的末尾,您需要:
PdfPTable table0
; float[] widths
扩展为包含两列以上的宽度;和E.g。像这样:
PdfPTable table0 = new PdfPTable(5);
float[] widths = new float[] { 7f, 0.5f, 4f, 0.5f, 7f };
table0.SetWidths(widths);
PdfPCell cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("b"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase(" = "));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("a"));
cell0.Rowspan = 2;
cell0.VerticalAlignment = Element.ALIGN_MIDDLE;
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
cell0 = new PdfPCell(new Phrase("c"));
cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table0.AddCell(cell0);
document.Add(table0);