2016-12-05 50 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