Column text overflowing out of column width

2020-03-28 17:50发布

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:

enter image description here

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

2条回答
Bombasti
2楼-- · 2020-03-28 18:22

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 enter image description here

查看更多
不美不萌又怎样
3楼-- · 2020-03-28 18:36

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.

查看更多
登录 后发表回答