Git Product home page Git Product logo

docxplus's Introduction

DocXPlus

Similar to DocX but based on the Open XML SDK instead of directly working with the underlying XML. The Open XML SDK is very powerful but requires a significant amount of coding. This library provides an abstraction layer greatly reducing the amount of code you have to write and maintain.

This initial phase is very much a minimum viable product, only implementing features as they are required. Currently there is no support for reading existing Word documents.

Stay tuned, under development

Build Status

Status
Build status

Some Code

Create Using Default Stream

using (var doc = new DocX())
{
    doc.Create();

    doc.AddParagraph().Append(LoremIpsum);

    using (var stream = new FileStream(filename, FileMode.Create))
    {
        doc.SaveAs(stream);
    }
}

Different Page Orientation After Section Break

var doc = DocX.Create(filename, DocumentType.Document);
doc.Orientation = PageOrientation.Landscape;

doc.AddParagraph().Append("Landscape");

doc.InsertSectionPageBreak();
doc.Orientation = PageOrientation.Portrait;

doc.AddParagraph().Append("Portrait");

doc.InsertSectionPageBreak();
doc.Orientation = PageOrientation.Landscape;

doc.AddParagraph().Append("Landscape");

doc.Close();

Different Headers and Footers After Section Break

var doc = DocX.Create(filename, DocumentType.Document);

doc.AddHeaders();
doc.AddFooters();

doc.DefaultHeader.AddParagraph().Append("Header 1");
doc.DefaultFooter.AddParagraph().Append("Footer 1");

doc.InsertSectionPageBreak();

doc.AddHeaders();
doc.AddFooters();

doc.DefaultHeader.AddParagraph().Append("Header 2");
doc.DefaultFooter.AddParagraph().Append("Footer 2");

doc.InsertSectionPageBreak();

doc.AddHeaders();
doc.AddFooters();

doc.DefaultHeader.AddParagraph().Append("Header 3");
doc.DefaultFooter.AddParagraph().Append("Footer 3");

doc.Close();

You can also add page numbers to the footer

doc.AddFooters();

doc.DefaultFooter
    .AddParagraph()
    .Append("Page ")
    .AppendPageNumber(PageNumberFormat.Normal)
    .Append(" of ")
    .AppendPageCount(PageNumberFormat.Normal)
    .Bold()
    .Alignment = Align.Center;

Tables

 var doc = DocX.Create(filename, DocumentType.Document);

var table = doc.AddTable(5);

for (int i = 0; i < 50; i++)
{
    var row = table.AddRow();
    row.SetBorders(Units.HalfPt, BorderValue.Single);

    if (i == 0)
    {
        // shade the first row and set as a header
        row.SetShading("E7E6E6");

        row.HeaderRow = true;
    }

    for (int j = 0; j < 5; j++)
    {
        row.Cells[j].Paragraphs[0].Append($"Cell {(j + 1)}");
    }
}

doc.Close();

docxplus's People

Contributors

glenconway avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.