代码之家  ›  专栏  ›  技术社区  ›  Ashutosh

列文本溢出,超出列宽

  •  2
  • Ashutosh  · 技术社区  · 8 年前

    我使用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+wert+2345+rg+2345+ag+35+qwe1252rg+34tgh+24rg+253rg+23rgh+235rgh+@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+wert+2345+rg+2345+ag+35+qwe+125+2rg+34tgh+24rg+253rg+23rgh+235rgh+@34gh+23rg-4s544");
    
    2 回复  |  直到 8 年前
        1
  •  4
  •   I liked the old Stack Overflow    6 年前

    MigraDoc会自动在空格、连字符和软连字符处断行。

    您有一个没有空格和连字符的长文本。简单的解决方案是:在希望出现换行符的位置插入软连字符(例如,在每个“+”符号后插入一个软连字符)。

    更新:从1.50版开始,您还可以使用零宽度非连接线来标记允许换行的位置。使用软连字符来获得带连字符的换行符,使用零宽度非连接符来获得没有连字符的断行符。

        2
  •  2
  •   Ashutosh    8 年前

    space 在每45个字符之后(根据列宽选择),因此该值被正确包装,不会对显示的输出产生任何影响(没有额外的字符可见)

    代码片段-

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

    输出 enter image description here