Column text overflowing out of column width

落爺英雄遲暮 提交于 2019-12-01 07:52:28

问题


I am using Migradoc to generate a table and populating some dynamic data for few columns, I have defined column width while defining table structure as-

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));

Now the third column is having data (acs800-07-1234a-5+asdf+asdf+qwer+wert+2345+rg+2345+ag+35+qwe1252rg+34tgh+24rg+253rg+23rgh+235rgh+@34gh+23rg-4s544) , but it's overflowing the column and getting truncated towards the right side of page. It's automatically wrapped but not correctly , some text is lost in the second line. See image:

Any pointers to fix this issue in wrapping text would be appreciated.

UPDATE- ( Snippet showing how table data is added)

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+wert+2345+rg+2345+ag+35+qwe+125+2rg+34tgh+24rg+253rg+23rgh+235rgh+@34gh+23rg-4s544");

回答1:


MigraDoc automatically breaks lines at spaces, hyphens, and soft hyphens.

You have a long text without spaces and without hyphens. The easy solution: insert soft hyphens where you want to allow line breaks to occur (e.g. a soft hyphen after each "+" sign).

Update: As of version 1.50 you can also use zero-width non-joiners to mark locations where line breaks are allowed. Use soft hyphens to get line breaks with a hyphen, use zero-width non-joiners for line breaks without hyphens.




回答2:


As Migradoc has limitation of breaking lines at only spaces,hyphens and soft hyphens i have inserted space after everyy 45 chars(your choice as per column width) and hence the value is wrapped properly without having any effect of shown output(no extra chars visible)

Code Snippet -

    String myString = "acs800-07-1234a-5+asdf+asdf+qwer+wert+2345+rg+2345+ag+35+qwe+125+2rg+34tgh+24rg+253rg+23rgh+235rgh+@34gh+23rg-4s544";

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

OUTPUT



来源:https://stackoverflow.com/questions/40973366/column-text-overflowing-out-of-column-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!