wordpress hit counter
Re: (Info)Table of Contents - WordprocessingML - Formats - OpenXML Developer

Re: (Info)Table of Contents

Formats

Discussions about working with different Open XML Formats

(Info)Table of Contents

  • rated by 0 users
  • This post has 14 Replies |
  • 2 Followers
  • To add Table of contents to your document click Table of Contents buttton of Table of Contents group of References tab.

    Table of contents are shown as a set of fields under Structured Document Tag.

    The property of bookmarks are used to link to a particular portion of document through Table of Contents.

    Consider,

    <w:sdt> 

         <w:sdtPr>

               <w:id w:val="458904407" />
                 <w:docPartObj>
                     <w:docPartType w:val="Table of Contents" />
                     <w:docPartUnique />
           </w:docPartObj>
      </w:sdtPr>
     
           <w:sdtContent>
                   <w:p>
                             <w:pPr>
                                    <w:pStyle w:val="TOCHeading1" />
                        </w:pPr>
                             <w:r>
                                    <w:t>Contents</w:t>
                        </w:r>
             </w:p>
                   <w:p>
                             <w:pPr>
                                    <w:pStyle w:val="TOC1" />
                                      <w:tabs>
                                             <w:tab w:val="right" w:leader="dot" w:pos="9350" />
                                 </w:tabs>
                             </w:pPr>
                              <w:r>
                                    <w:fldChar w:fldCharType="begin" />
                        </w:r>
                              <w:r>
                                    <w:instrText xml:space="preserve">TOC \o "1-3" \h \z \u</w:instrText>
                        </w:r>
                              <w:r>
                                    <w:fldChar w:fldCharType="separate" />
                        </w:r>
                              <w:hyperlink w:anchor="_Toc155526688" w:history="1">
                                      <w:r>
                                               <w:rPr>
                                                         <w:rStyle w:val="Hyperlink" />
      
                                          </w:rPr>
                                             <w:t>Topic 1</w:t>
                                 </w:r>
                                       <w:r>
                                                   <w:tab />
                                  </w:r>
                                        <w:r>
                                             <w:fldChar w:fldCharType="begin">
                                                   <w:fldData xml:space="preserve">CNDJ6nn5us4RjIIAqgBLqQsCAAAACAAAAA4AAABfAFQAbwBjADEANQA1ADUAMgA2ADYAOAA4AAAA</w:fldData>
                                       </w:fldChar>
                                  </w:r>
                                        <w:r>
                                        <w:instrText xml:space="preserve">PAGEREF _Toc155526688 \h</w:instrText>
                                  </w:r>
                                        <w:r>
                                         <w:fldChar w:fldCharType="separate" />
                                  </w:r>
                     <w:r>
                   <w:t>2</w:t>
                                  </w:r>
                                       <w:r>
                                       <w:fldChar w:fldCharType="end" />
                                  </w:r>
            </w:hyperlink>
      </w:p>
       ---
                ---
     
     </w:sdtContent>
    </w:sdt>

    As you can see we have a document part object of type Table of Contents,defined in the node 'docPartObj'.

    The contents of table of contents appear in the content portion of the Structured Document Tag

    node 'pStyle' suggests the style to be used which is in turn defined in 'styles.xml'

    'fldChar' specifies that a field character shall be placed at this location in the document,which would be the page number of each topic.

    Here,the appearance of the table of contents is defined by

    <w:tabs>

                 <w:tab w:val="right" w:leader="dot" w:pos="9350" />
     </w:tabs>
     
    which means,you can include space of value specified above and the tabs are filled with dots.
     
    ' TOC \o "1-3" \h \z \u ' builds Table of contents,where the switches \o defines the heading style to be used (here headings 1 to 3),
     \h, Makes the table of contents entries hyperlinks.
      \z,Hides tab leader and page numbers in Web layout view.
    \u,Uses the applied paragraph outline level.
     
    'hyperlink ' links to a particular topic from table of contents to the entire topic in the document with the help of the anchor attribute
    and 'PAGEREF _Toc155526688 \h' ,inserts the number of the page containing the bookmark specified by text in field-argument .Switch \h makes it a hyperlink
     
    The region where the entire topic is present is bookmarked using the same value as used in in the attribute anchor of tag 'hyperlink'
     
                <w:p>
                               <w:pPr>
                                       <w:outlineLvl w:val="0" />
                         </w:pPr>
                             <w:bookmarkStart w:id="1" w:name="_Toc155526688" />
                                          <w:r>
                                                      <w:t>Topic 1</w:t>
                                     </w:r>
                              <w:bookmarkEnd w:id="1" />
     
                    </w:p>
       
          
     
     
     
  • Hey is this still correct?  I'm looking to generate a TOC and INDEX automatically and I was hoping there was an easier way then generating all the hyperlinks manually.  Any advice you have would be appreciated.  Right now these are the two final pieces of the puzzle I have left.  I've managed to produce and incredibly complex report, over a hundred pages of embedded images, HTML, text and Index Entries, but I am required to have a cradle to grave solution that includes TOC and INDEX. 
  • Hi,

    Yes, you need to create hyperlinks for each of the items in the content. Either you generate automatically or manually, the bookmark and hyperlinks in TOC are interlinked.

    Sheela

  • Hi,

    In an application, I generate automatically a Word document using OpenXML with TOC, but page numbers are not created (or updated if I use a templateto generate my document)...

    The matter is that since I don't use Word to generate my document, I could not use <w:lastRenderedPageBreak /> tags, so I have no idea of how to find in which page titles are.

    Do you know how to do?

    Ludo.

  • Hi,

    Since page no (no. of pages) depends on the page layout, it will be difficult to determine

    the page no automatically to put in TOC. But, the point is hyperlinked item is not the page

    no, it is the book mark created, hence you can link hyperlink and the book mark with random

    number. I aggree, TOC numbers will not be in sync with the number pages in word document.

     

    I guess, it will be difficult to create TOC with exact page numbers.

     

    Sheela

  • Wow it took me less than a day to implement my Table Of Contents.  The hardest part was tracking down one missing fldChar.  I only wish I could get the page numbers to populate automatically upon first opening, but I will probably tackle that issue with Word automation; unless anyone has some suggestions there too?
  • I'm creating a document using wordprocessingml for Word 2003.

    Is there an easier way to create a TOC, but without the hyperlinks?  That is, create a TOC based on the location of my headings without hyperlinks to the sections?

    It would also be great if the page numbers were auto-updated when the document was opened without having any user interaction.

    Thanks, Mike

  • Can you plz help me in creating table of contents using openxml. I am really worried about this, as I have no idea on how to do this. I could able to create a document using openxml and C#, this also should have table of contents. plz suggest me how to do this, if you have sample code, can you plz post it here.
    Thanks,
    Ramakrishna
  • the answer for the 2nd question is no. page numbers cannot be auto-updated.
  • I've written some code, and recorded some screen-casts that explain TOC markup in detail:

    openxmldeveloper.org/.../exploring-tables-of-contents-in-open-xml-wordprocessingml-documents.aspx

    -Eric

  • Hi...,

    Numbering in table of contents into docx file is not incrementing order and PAGEREF linking is working fine.

    I am facing this issue, how to increment the table of contenets number.

    Ex : Right side number should be incrementing order, i am using WordProcessingML

                                Table Of Contents

    1  Purpose and scope ........................................................1

    2  Executive ...........................................................................1

    3  Batches .............................................................................1

    4  materials performance...................................................1

         4.1 Sources.....................................................................1

         4.2 Vendor ......................................................................1

    Can u pls look into the bellow code and help me out this issue.  I have tried bellow code in java using WordProcessingML.

    public static StringBuffer addTOCEntry(StringBuffer strBuffer,

      String templateName, String heading, String headingOrder,

      String headingBookMark, String tocStyle)  {

     // Add the templates

     strBuffer.append(" <xsl:template name=" + "\""

         + templateName

         + "\"> "

         + "  <w:p >   "

         + "   <w:pPr>   "

         + "    <w:pStyle w:val="

         + "\""

         + tocStyle

         + "\" />    "

         + "   <w:rPr>  "

         + "     <w:rFonts w:asciiTheme=\"minorHAnsi\" w:eastAsiaTheme=\"minorEastAsia\" w:hAnsiTheme=\"minorHAnsi\" w:cstheme=\"minorBidi\" />  "

         + "    <w:noProof />   "

         + "    <w:sz w:val=\"22\" />   "

         + "     <w:szCs w:val=\"22\" />   "

         + "     </w:rPr>  "

         + "    </w:pPr>  "

         + "   <w:r>  "

         + "   <w:rPr>  "

         + "    <w:noProof />   "

         + "     </w:rPr>  "

         + "     <w:t>"

         + headingOrder

         + "   </w:t>   "

         + "   </w:r>  "

         + "   <w:r>  "

         + "   <w:rPr>  "

         + "     <w:rFonts w:asciiTheme=\"minorHAnsi\" w:eastAsiaTheme=\"minorEastAsia\"  w:hAnsiTheme=\"minorHAnsi\" w:cstheme=\"minorBidi\" />  "

         + "     <w:noProof />   "

         + "     <w:sz w:val=\"22\" />   "

         + "     <w:szCs w:val=\"22\" />   " + "   </w:rPr>  "

         + "     <w:tab />   " + "     </w:r>  " + "    <w:r>  "

         + "     <w:rPr>  " + "     <w:noProof />   "

         + "     </w:rPr>  " + "     <w:t>" + heading

         + "     </w:t>   " + "     </w:r>  " + "    <w:r>  "

         + "     <w:rPr>  " + "    <w:noProof />   "

         + "     </w:rPr>  " + "     <w:tab />   "

         + "     </w:r>  " + "    <w:r>  " + "    <w:rPr>  "

         + "    <w:noProof />   " + "   </w:rPr>  "

         + "    <w:fldChar w:fldCharType=\"begin\" />   "

         + "    </w:r>  " + "    <w:r>  " + "    <w:rPr>  "

         + "    <w:noProof />   " + "     </w:rPr>  "

         + "     <w:instrText xml:space=\"preserve\">PAGEREF "

         +       headingBookMark + " \\h </w:instrText>   "

         + "     </w:r>  " + "    <w:r>  " + "    <w:rPr>  "

         + "     <w:noProof />   " + "     </w:rPr>  "

         + "     </w:r>  " + "    <w:r>  " + "    <w:rPr>  "

         + "    <w:noProof />   " + "     </w:rPr>  "

         + "     <w:fldChar w:fldCharType=\"separate\" />   "

         + "     </w:r>  " + "    <w:r>  " + "   <w:rPr>  "

         + "    <w:noProof />   " + "    </w:rPr>  "

         + "    <w:t>1</w:t>   " + "    </w:r>  "

         + "    <w:r>  " + "    <w:rPr>  "

         + "   <w:noProof />   " + "    </w:rPr>  "

         + "    <w:fldChar w:fldCharType=\"end\" />   "

         + "    </w:r>  " + "    </w:p>  "

         + "  </xsl:template>  ");

     return strBuffer;

    }

    Thanks & Regards,

    Ramana.

  • You may need to update the field once it is open in Word. If that doesn't work, let me know and I will look at it closer.

  • Thanks for your replay...

    if we use w:dirty="true" tag inside fldCharType for both 'begin' and 'end', It is asking update the fields in this  document or not.

    While opening docx file it is asking " Do you want to update the fields in this document ".

    If we click 'yes' button, Update Table of Content dialog box is coming for several times if we click 'OK' button.

    Without asking update line number dialog box, How to increment the number in table of contents.(if it is possible without w:dirty="true" tag).

    Please help me out for this issue.

    Ex:

        <w:r>

         <w:fldChar w:fldCharType="begin" w:dirty="true" />

        </w:r>

        <w:r>

         <w:instrText xml:space="preserve">TOC \o "1-3" \h \z \u</w:instrText>

        </w:r>

        <w:r>

         <w:fldChar w:fldCharType="separate" />

        </w:r>

    Thanks & Regards,

    Ramana.

  • How to update the numbers in TOC using wordprocessingML without usign w:dirty tag?

  • Please look at Eric White's screen-casts referenced in his reply. They are very detailed and I believe they will answer your questions.

Page 1 of 1 (15 items)