Hello Eric,
I have requirement of adding table of contents to second page of word document while exporting using Html string. My first page will always be Cover page. Below is the code which I am using currently for adding table of contents, currently it was adding to first page only. Please do needful and update me asap.
using (WordprocessingDocument wdoc =
WordprocessingDocument.Open(Filepath, true))
{
AddSettingsToMainDocumentPart(wdoc.MainDocumentPart);
XElement firstPara = wdoc.MainDocumentPart.GetXDocument().Descendants(W.altChunk).FirstOrDefault();
OpenXmlPowerTools.TocAdder.AddToc(wdoc, firstPara,
@”TOC \o ‘1-3’ \h \z \u”, null, null);
}
public void AddSettingsToMainDocumentPart(MainDocumentPart part)
{
if (part.DocumentSettingsPart == null)
{
DocumentSettingsPart settingsPart = part.AddNewPart<DocumentSettingsPart>();
FileStream settingsTemplate = new FileStream(Server.MapPath(“~/Context/settings.xml”), FileMode.Open, FileAccess.Read);
settingsPart.FeedData(settingsTemplate);
settingsPart.Settings.Save();
}
}