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
280 stars 50 forks source link

Adds AddBreak() method to Paragraphs #39

Closed PrzemyslawKlys closed 1 year ago

PrzemyslawKlys commented 1 year ago

Should solve

image

public static void Example_BasicWordWithBreaks(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with paragraph & breaks");
    string filePath = System.IO.Path.Combine(folderPath, "BasicDocumentWithParagraphsAndBreaks.docx");
    using (WordDocument document = WordDocument.Create(filePath)) {
        var paragraph1 = document.AddParagraph("Adding paragraph1 with some text and pressing ENTER");

        var paragraph2 = document.AddParagraph("Adding paragraph2 with some text and pressing SHIFT+ENTER");
        paragraph2.AddBreak();
        paragraph2.AddText("Continue1");
        paragraph2.AddBreak();
        paragraph2.AddText("Continue2");

        var paragraph3 = document.AddParagraph("Adding paragraph3 with some text and pressing ENTER");

        document.Save(openWord);
    }
}

Additionally:

document.Breaks[0].Remove();
document.Breaks[0].Remove(includingParagraph: true);
hisuwh commented 1 year ago

Would love to see this merged ❤️

PrzemyslawKlys commented 1 year ago

@hisuwh need to write some tests over the weekend and will merge both PRs.

hisuwh commented 1 year ago

Nice one for getting this in. Any chance you can publish a new version with this change?

PrzemyslawKlys commented 1 year ago

I am waiting for your PR for a stream ;p