1

I am using novacode docx library from c# for generating document, I want to know how to add headings in document and link them in Table of content.

SameerK
  • 21
  • 3

1 Answers1

0

Personally i am using a template document with some title define text and some tag like :

  1. [TITLE 1]

Then, i am using something like this :

using (document = DocX.Load(TEMPLATE_LOCATION))
{
    #region Static data

    //Get datas from the ressource files and translate tag
    ResourceSet resourceSet = StaticLabels.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
    foreach (DictionaryEntry entry in resourceSet)
    {

        string resourceKey = entry.Key.ToString();
        string resource = (string)entry.Value;
        document.ReplaceText(resourceKey, resource);
    }

    #endregion //Static Data

    #region Add Table of content

    document.InsertDefaultTableOfContents();

    #endregion //Table of content

}

The ressource file contains [TITLE 1] and some texte to replace it

You can also simply use :

document.ReplaceText("[TITLE]", "My Title");
G.Dealmeida
  • 325
  • 3
  • 14