Insert table of contents


#1

I just downloaded the trial version of Aspose.Word 1.7. I would like to generate a word document from a SQL Server database or import from existing <?xml:namespace prefix = st1 ns = "urnTongue Tiedchemas-microsoft-comSurprisefficeTongue Tiedmarttags" /><st1:City wTongue Tiedt="on"><st1Stick out tonguelace wTongue Tiedt="on">Crystal</st1Stick out tonguelace> report, and then generate the TOC (Table of Contents) including the page number based on the data within the document. Do you have any example to do this? I need this to be working before I can submit a proposal to purchase the software.<?xml:namespace prefix = o ns = "urnTongue Tiedchemas-microsoft-comSurprisefficeSurpriseffice" /><oStick out tongue></oStick out tongue>

<oStick out tongue> </oStick out tongue>

Thanks<oStick out tongue></oStick out tongue>

-Thi<oStick out tongue></oStick out tongue>


#2

As another customer has just found out - Crystal reports does not save in MS Word format, it just saved in RTF format and gives .doc extension, see http://www.aspose.com/forums/ShowPost.aspx?PostID=10506. We will have support for RTF import in the near future.

You can insert table of contents field using DocumentBuilder.InsertTableOfContents, but I must admit its usefulness is limited as when you open the file in MS Word, the fields are not automatically updated unless you select a field (or select all document) and hit F9.

//This is how to insert a TOC field.
Document doc = TestUtil.Open(@“DocBuilder\TestDocBuilderAdvancedTOC.doc”);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertTableOfContents(@"\o ““1-3"” \h \z \u”);
doc = TestUtil.SaveOpen(doc, @“DocBuilder\TestDocBuilderAdvancedTOC Out.doc”);

If you are okay that the recipient of the document needs to update the fields in the document on open, then that’s the way to go. If not, then you can try to “manually” create a table of contents for a document using DocumentBuilder. But this is of course difficult if you want the TOC to show page numbers as you don’t know page numbers unless your document is of some fixed layout.