2016-12-05 22 views
1

我使用Migradoc以生成表并填充几列一些动态数据,我已经定义列的宽度,同时限定表结构原样列文本满溢出来柱的宽度

Table table = new Table(); 
Column column = table.AddColumn(Unit.FromCentimeter(6)); 
column.Format.Alignment = ParagraphAlignment.Left; 
table.AddColumn(Unit.FromCentimeter(6)); 
table.AddColumn(Unit.FromCentimeter(8)); 

现在第三列是有数据(acs800-07-1234a-5+asdf+asdf+qwer+w[email protected]34gh+23rg-4s544),但它溢出列并被截断到页面的右侧。它会自动包装但不正确,某些文字在第二行中丢失。见图片:

enter image description here

任何指针来解决这个问题,在文本换行,将不胜感激。

更新 -(摘录示出表的数据是如何被添加)

Row row = table.AddRow(); 
Cell cell = row.Cells[0]; 
cell.AddParagraph("ACS880-104"); 
cell = row.Cells[1]; 
cell.AddParagraph("R1 – R10"); 
cell = row.Cells[2];    
cell.AddParagraph("acs800-07-1234a-5+asdf+asdf+qwer+wer[email protected]34gh+23rg-4s544"); 
+0

如何将文本添加到表格中? “段落”? 'FormattedText'? 'TextFrame'? –

+0

这是一个真正的单词类型代码,还是在使用真实数据时会有空格和连字符? –

+0

@MongZhu我正在使用段落添加文本 - 也更新了代码片段 – Ashutosh

回答

3

MigraDoc自动断开在空格,连字符和软连字符线。

您的文字很长,没有空格,也没有连字符。简单的解决方案:在想要允许换行的地方插入软连字符(例如,在每个“+”符号后加一个软连字符)。

+0

是的这是真实世界的数据,你能解释一下我们如何插入并在包装后删除这些软连字符? – Ashutosh

+0

我已经探索了与我自己的软连字符的东西,并在以下贴出我的解决方案,感谢指向正确的方向。 – Ashutosh

1

由于Migradoc在仅有空格,连字符和软连字符处有断行限制,因此我在每45个字符(根据列宽选择您的选择)后插入space,因此该值被正确包装而没有任何显示输出的影响没有多余的字符可见)

代码片段 -

String myString = "acs800-07-1234a-5+asdf+asdf+qwer+wer[email protected]34gh+23rg-4s544"; 

    cell.AddParagraph(Regex.Replace(myString, ".{45}", "$0 ")); 

输出 enter image description here