MigraDoc C#左对齐,右同一行 [英] MigraDoc C# Align left and right on same line
问题描述
我有一个细胞,其中i想要两个文本中,第一,在左侧和右侧对齐,在相同的小区,在同一行上的第二对准的表
I have a table with a cell where i want two texts, the first, aligned on left and the second aligned on the right, in the same cell, on the same line.
我试图重现此电池与MigraDoc没有成功。我只可以添加在左侧和右侧,但不是在同一线上两个文本
I tried to reproduce this cell with MigraDoc without success. I only can add two texts aligned on left and right but not on same line.
下面我的代码:
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 ),但我不能做同样与我的表。我不明白它是如何工作的。
A solution is presented here (http://forum.pdfsharp.net/viewtopic.php?f=2&t=2373) but I'm not able to do same with my table. I don't understand how it work.
编辑:部分解决方案:
一个艰苦的工作去了解它是如何工作后,我的代码部分工作。部分是因为我发现右对齐的唯一途径就是创造一个接受tab具有近似的价值......不是很好。
After a hard work to understand how it work, my code is partially working. partial because the only way I found to right align is to creat a TabStop with an approximative value... not fine.
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是行不通的。
It work but how to find the good value for the AddTab function ? I put 67 because 68to70 is not working.
推荐答案
诀窍在链接后显示的是相当简单:你只需要一个段落,左对齐
The trick shown in the linked post is rather simple: you only need a single paragraph, left-aligned.
然后确保有只定义了一个制表位,右对齐制表位在单元格的右边缘。
Then make sure there is only one tabstop defined, a right-aligned tabstop at the right edge of the cell.
段落,添加文本你要左对齐,然后添加一个制表位,然后添加文本你想右对齐
To the paragraph, add the text you want left-aligned, then add a tabstop, then add the text you want right-aligned.
示例代码:
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;
这篇关于MigraDoc C#左对齐,右同一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!