我有一个带有单元格的表格,我想要两个文本,第一个在左边对齐,第二个在右边,在同一个单元格中,在同一行上 .
我试图用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);
这里给出了一个解决方案(http://forum.pdfsharp.net/viewtopic.php?f=2&t=2373),但我理解它是如何工作的 .
Edit : Partial solution :
在努力了解它是如何工作之后,我的代码部分正常工作 . 部分因为我发现右对齐的唯一方法是创建一个具有近似值的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函数的好 Value ?我把 67 因为68to70无效 .
3 回答
链接帖子中显示的技巧相当简单:你只需要一个左对齐的段落 .
然后确保只定义了一个tabstop,在单元格的右边缘有一个右对齐的tabstop .
在段落中,添加您想要左对齐的文本,然后添加一个tabstop,然后添加您想要右对齐的文本 .
示例代码:
在单行上,您可以"correct"行高, SpaceAfter 属性等于fontsize的负值 .
示例RightAlignedTitle样式:
示例代码:
这是另一种方式...在发票应用程序中使用,其中数字右对齐,项目描述左对齐 .