MS Word Document File Generates Index

I use phpword to create an MS Word document, is there a way to help me generate an index at the end of the generated file?

one of the ways that I think it can work is to read the generated MS Word file and find where each word is (for example, the page number in the MS Word file), and then restore the index in a separate MS Word file.

Is there a better way?
Example of the required file:

A 
Animal 51,98 
Apple 11,54,99 

B
Basket 55  
...
..
etc
+5
source share
3 answers

I suppose you could read the headings of the document: read this post, this is not quite what you want, but it might be correct with the changes:

+1

,

.

+1

, shox, , . , phpword, , . docx ( zip ) XML . , ... , , , Word . " " . :

~/[Content_Types].xml:

<Override PartName="/customXml/itemProps1.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml" />

~/CustomXml -

~/CustomXml item1.xml:

<b:Sources SelectedStyle="\APA.XSL" StyleName="APA" xmlns:b="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"></b:Sources>

~/CustomXml itemProps1.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ds:datastoreItem ds:itemID="{3DC430FE-7F6E-49D7-9EFC-E4F37E42ABA0}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml">
  <ds:schemaRefs>
     <ds:schemaRef ds:uri="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"/>
  </ds:schemaRefs>
</ds:datastoreItem>

~/CustomXml/_rels: ~/CustomXml/_rels item1.xml.rels:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps" Target="itemProps1.xml"/>
</Relationships>

~/docProps , , / /, .

, ~/word. , ~/word/styles.xml , , :

<w:style w:type="paragraph" w:styleId="Index1">
  <w:name w:val="index 1"/>
  <w:basedOn w:val="Normal"/>
  <w:next w:val="Normal"/>
  <w:autoRedefine/>
  <w:uiPriority w:val="99"/>
  <w:semiHidden/>
  <w:unhideWhenUsed/>
  <w:rsid w:val="00C52B35"/>
  <w:pPr>
    <w:spacing w:after="0" w:line="240" w:lineRule="auto"/>
    <w:ind w:left="220" w:hanging="220"/>
  </w:pPr>
</w:style>

w: rsid ~/word/settings.xml , , , , , / .

~/word/_rels/document.xml.rels node :

<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml" Target="../customXml/item1.xml"/>

, , , ~/word/document.xml, ( "" ) :

<w:r w:rsidR="00C52B35">
  <w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r w:rsidR="00C52B35">
  <w:instrText xml:space="preserve">XE "</w:instrText>
</w:r>
<w:r w:rsidR="00C52B35" w:rsidRPr="00C90937">
  <w:instrText>sit</w:instrText>
</w:r>
<w:r w:rsidR="00C52B35">
  <w:instrText xml:space="preserve">"</w:instrText>
</w:r>
<w:r w:rsidR="00C52B35">
  <w:fldChar w:fldCharType="end"/>
</w:r>

, :

<w:p w:rsidR="00C52B35" w:rsidRDefault="00C52B35" w:rsidP="00DE5AB4">
  <w:pPr>
    <w:rPr>
      <w:b/>
      <w:noProof/>
    </w:rPr>
    <w:sectPr w:rsidR="00C52B35" w:rsidSect="00C52B35">
      <w:pgSz w:w="12240" w:h="15840"/>
      <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
      <w:cols w:space="720"/>
      <w:docGrid w:linePitch="360"/>
    </w:sectPr>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:fldChar w:fldCharType="begin"/>
  </w:r>
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:instrText xml:space="preserve">INDEX \c "2" \z "1033"</w:instrText>
  </w:r>
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:fldChar w:fldCharType="separate"/>
  </w:r>
</w:p>
<w:p w:rsidR="00C52B35" w:rsidRDefault="00C52B35">
  <w:pPr>
    <w:rPr>
      <w:noProof/>
    </w:rPr>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:noProof/>
    </w:rPr>
    <w:lastRenderedPageBreak/>
    <w:br w:type="page"/>
  </w:r>
</w:p>
<w:p w:rsidR="00C52B35" w:rsidRDefault="00C52B35">
  <w:pPr>
    <w:pStyle w:val="Index1"/>
    <w:tabs>
      <w:tab w:val="right" w:leader="dot" w:pos="4310"/>
    </w:tabs>
    <w:rPr>
      <w:noProof/>
    </w:rPr>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:noProof/>
    </w:rPr>
    <w:lastRenderedPageBreak/>
    <w:t>sit, 1, 2</w:t>
  </w:r>
</w:p>
<w:p w:rsidR="00C52B35" w:rsidRDefault="00C52B35" w:rsidP="00DE5AB4">
  <w:pPr>
    <w:rPr>
      <w:b/>
      <w:noProof/>
    </w:rPr>
    <w:sectPr w:rsidR="00C52B35" w:rsidSect="00C52B35">
      <w:type w:val="continuous"/>
      <w:pgSz w:w="12240" w:h="15840"/>
      <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
      <w:cols w:num="2" w:space="720"/>
      <w:docGrid w:linePitch="360"/>
    </w:sectPr>
  </w:pPr>
</w:p>
<w:p w:rsidR="00371DB1" w:rsidRPr="00371DB1" w:rsidRDefault="00C52B35" w:rsidP="00DE5AB4">
  <w:pPr>
    <w:rPr>
      <w:b/>
    </w:rPr>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:b/>
    </w:rPr>
    <w:lastRenderedPageBreak/>
    <w:fldChar w:fldCharType="end"/>
  </w:r>
</w:p>

, . , , , , . , , , . , , WinMerge, ( Compare Special > XML, ), . , . , , .

+1

All Articles