EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
279 stars 49 forks source link

Wrap text #112

Closed geraluca closed 1 year ago

geraluca commented 1 year ago

I have a problem with text strings, if in the text of a paragraph or in a table I want to wrap a part of my text (in vb.net Vbcrlf), how should I do it? Thank you

PrzemyslawKlys commented 1 year ago

I believe what you want is:

wordTable.AllowTextWrap = true;

For paragraphs with Images

var pargraphWithImage = paragraph.AddImage(file, 100, 100, WrapTextImage.InLineWithText, "Przemek and Kulek on an image");

I am not aware of any other TextWrapping methods applicable to paragraphs, but I could be wrong.

geraluca commented 1 year ago

I think I explained myself badly, if in a text to be placed in a paragraph, I have to go to the next line, without joining two paragraphs but remaining in the same one, how do you do it? Thank you

PrzemyslawKlys commented 1 year ago
            var paragraph = document.AddParagraph("Basic paragraph - Page 4");
            paragraph.ParagraphAlignment = JustificationValues.Center;
            paragraph.Color = SixLabors.ImageSharp.Color.Blue;
            paragraph.AddText("Test2");
            paragraph.AddBreak(BreakValues.TextWrapping);
            paragraph.AddText(" This is continuation").SetUnderline(UnderlineValues.Double).SetFontSize(15).SetColor(Color.Yellow).SetHighlight(HighlightColorValues.DarkGreen);

            var paragraph1 = document.AddParagraph("Basic paragraph - Page 1").AddText(" Ok ").AddBreak(BreakValues.TextWrapping).AddText("More text");

Keep in mind that WordParagraph is actually a "Run" in Office OpenXML. It's not 1:1 to Paragraph.