Saturday, March 2, 2024
HomePowershellOfficeIMO - Free cross-platform Microsoft Phrase .NET library

OfficeIMO – Free cross-platform Microsoft Phrase .NET library


Whereas the above examples are fairly easy OfficeIMO characteristic set for Phrase has much more to supply. Including sections, headers, and footers, altering web page dimension, and web page orientation. Including watermark, including a canopy web page, including a desk of content material, including lists, including tables, and a lot extra. You’ll be able to see within the beneath instance quite a lot of these options proven, and the way most of them are mainly one line of code.

public static void Example_AdvancedWord(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating superior doc");
    string filePath = System.IO.Path.Mix(folderPath, "AdvancedDocument.docx");
    utilizing (WordDocument doc = WordDocument.Create(filePath)) {
        // lets add some properties to the doc
        doc.BuiltinDocumentProperties.Title = "Cowl Web page Templates";
        doc.BuiltinDocumentProperties.Topic = "How one can use Cowl Pages with TOC";
        doc.ApplicationProperties.Firm = "Evotec Companies";

        // we power doc to replace fields on open, this can be utilized by TOC
        doc.Settings.UpdateFieldsOnOpen = true;

        // lets add one in every of a number of added Cowl Pages

        // lets add Desk of Content material (1 of two)

        // lets add web page break

        // lets create a listing that can be binded to TOC
        var wordListToc = doc.AddTableOfContentList(WordListStyle.Headings111);

        wordListToc.AddItem("How one can add a desk to doc?");

        doc.AddParagraph("Within the first paragraph I wish to present you  add a desk to the doc utilizing one of many 105 built-in types:");

        // including a desk and modifying content material
        var desk = doc.AddTable(5, 4, WordTableStyle.GridTable5DarkAccent5);
        desk.Rows[3].Cells[2].Paragraphs[0].Textual content = "Including textual content to cell";
        desk.Rows[3].Cells[2].Paragraphs[0].Colour = Colour.Blue; ;
        desk.Rows[3].Cells[3].Paragraphs[0].Textual content = "Totally different cell";

        doc.AddParagraph("As you may see including a desk with some model, and including content material to it ").SetBold().SetUnderline(UnderlineValues.Dotted).AddText("isn't actually sophisticated").SetColor(Colour.OrangeRed);

        wordListToc.AddItem("How one can add a listing to doc?");

        var paragraph = doc.AddParagraph("Including lists is much like ading a desk. Simply outline a listing and add record gadgets to it. ").SetText("Bear in mind which you can add something between record gadgets! ");
        paragraph.SetColor(Colour.Blue).SetText("For instance TOC Checklist is simply one other record, however defining a selected model.");

        var record = doc.AddList(WordListStyle.Bulleted);
        record.AddItem("First component of record", 0);
        record.AddItem("Second component of record", 1);

        var paragraphWithHyperlink = doc.AddHyperLink("Go to Evotec Blogs", new Uri(""), true, "URL with tooltip");
        // you can too change the hyperlink textual content, uri afterward utilizing properties
        paragraphWithHyperlink.Hyperlink.Uri = new Uri("");
        paragraphWithHyperlink.ParagraphAlignment = JustificationValues.Heart;

        record.AddItem("third component of record, however added after hyperlink", 0);
        record.AddItem("4th component with hyperlink ").AddHyperLink("included.", new Uri(""), addStyle: true);


        var listNumbered = doc.AddList(WordListStyle.Heading1ai);
        listNumbered.AddItem("Totally different record number one");
        listNumbered.AddItem("Totally different record quantity 2", 1);
        listNumbered.AddItem("Totally different record quantity 3", 1);
        listNumbered.AddItem("Totally different record quantity 4", 1);

        var part = doc.AddSection();
        part.PageOrientation = PageOrientationValues.Panorama;
        part.PageSettings.PageSize = WordPageSize.A4;

        wordListToc.AddItem("Including headers / footers");

        // lets add headers and footers

        // including textual content to default header
        doc.Header.Default.AddParagraph("Textual content added to header - Default");

        var section1 = doc.AddSection();
        section1.PageOrientation = PageOrientationValues.Portrait;
        section1.PageSettings.PageSize = WordPageSize.A5;

        wordListToc.AddItem("Including customized properties and web page numbers to doc");

        doc.CustomDocumentProperties.Add("TestProperty", new WordCustomProperty { Worth = DateTime.Right now });
        doc.CustomDocumentProperties.Add("MyName", new WordCustomProperty("Some textual content"));
        doc.CustomDocumentProperties.Add("IsTodayGreatDay", new WordCustomProperty(true));

        // add web page numbers

        // add watermark
        doc.Sections[0].AddWatermark(WordWatermarkStyle.Textual content, "Draft");





Please enter your comment!
Please enter your name here

Most Popular

Recent Comments