我有一个带有单元格的表格,其中我想要两个文本,第一个文本左对齐,第二个文本右对齐,位于同一单元格的同一行上。
我尝试使用 MigraDoc 重现此单元,但没有成功。我只能添加左右对齐的两个文本,但不能在同一行上。
这是我的代码:
Cell cellFooter1 = rowFooter.Cells[0];
Paragraph paraphTot = new Paragraph();
paraphTot.Format.Alignment = ParagraphAlignment.Left;
paraphTot.AddText("Left text");
cellFooter1.Add(paraphTot);
Paragraph paraphDetails = new Paragraph();
paraphDetails.Format.Alignment = ParagraphAlignment.Right;
paraphDetails.AddText("Right text");
cellFooter1.Add(paraphDetails);
这里提出了一个解决方案()但我无法对我的桌子做同样的事情。我不明白它是如何工作的。
编辑:部分解决方案:
经过努力了解其工作原理后,我的代码部分工作了。部分因为我发现右对齐的唯一方法是创建一个具有近似值的 TabStop...不好。
Table table = new Table();
table.Borders.Width = 0.75;
Column myColumn = table.AddColumn(Unit.FromCentimeter(7));
Row myRow = table.AddRow();
Cell myCell = myRow.Cells[0];
Paragraph myParagraph = new Paragraph();
Style myStyle = doc.AddStyle("myStyle", "Normal");
myStyle.ParagraphFormat.Font.Size = 6.5;
myStyle.ParagraphFormat.Font.Bold = true;
myStyle.ParagraphFormat.TabStops.Clear();
myStyle.ParagraphFormat.AddTabStop(Unit.FromMillimeter(67), TabAlignment.Right);
myParagraph.Style = "myStyle";
myParagraph.Format.Alignment = ParagraphAlignment.Left;
myParagraph.AddFormattedText("left", "myStyle");
myParagraph.AddTab();
myParagraph.AddFormattedText("right", "myStyle");
myCell.Add(myParagraph);
它可以工作,但如何找到 AddTab 函数的良好值?我放67因为 68to70 不起作用。
链接帖子中显示的技巧相当简单:您只需要一个左对齐的段落。
然后确保只定义了一个制表位,即单元格右边缘的右对齐制表位。
在段落中,添加要左对齐的文本,然后添加制表位,然后添加要右对齐的文本。
示例代码:
var table = section.AddTable();
table.AddColumn("8cm");
table.AddColumn("8cm");
var row = table.AddRow();
var paragraph = row.Cells[0].AddParagraph("Left text");
paragraph.AddTab();
paragraph.AddText("Right text");
paragraph.Format.ClearAll();
// TabStop at column width minus inner margins and borders:
paragraph.Format.AddTabStop("7.7cm", TabAlignment.Right);
row.Cells[1].AddParagraph("Second column");
table.Borders.Width = 1;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)