2012-09-29 20 views
5

Io uso phpword per generare un documento MS Word, c'è qualche modo di aiutarmi a generare un indice alla fine del file generato?Il file di documento MS Word genera l'indice

un modo che penso possa funzionare, è leggere il file MS Word generato e individuare dove ogni parola è (ad esempio il numero di pagina nel file MS Word) e quindi rigenerare l'indice in un file MS Word separato.

Esiste un metodo migliore?
Esempio del file richiesto:

A 
Animal 51,98 
Apple 11,54,99 

B 
Basket 55 
... 
.. 
etc 
+0

Quanto è grande quel documento? Quanti documenti devi lavorare? Questo è solo un file da generare o devi creare un sistema che genera indici anche in un secondo momento? – Kamil

+0

@Kamil un solo file di parole, il primo file generato circa 200 pagine. – shox

risposta

1

I supose si poteva leggere le intestazioni del documento: leggere questo post, non è esattamente ciò che si vuole, ma forse con modifiche potrebbe essere il modo corretto:

Automatically generate nested table of contents based on heading tags

+0

I collegamenti possono [rot] (http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers)! Fornire una breve informazione sul collegamento e aggiungerlo come riferimento –

1

penso che questo vi aiuterà a

See Here

+0

I collegamenti possono [rot] (http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really -Buona-risposte)! Fornisci una breve informazione sul link e aggiungilo come riferimento –

+0

@Bhuvan Rikka ok thankz per le tue informazioni ............ – Kichu

+0

@BhuvanRikka 웃, consulta questo 'http://stackoverflow.com/questions/15496461/usps-not-working-magento-1-7-ce' prova a trovare una soluzione ....... – Kichu

1

Onestamente, shox, non penso che tu abbia molte buone opzioni qui. Ho esaminato un po 'questo aspetto perché è interessante anche per me, ma non ho trovato nulla nei documenti o nei forum phpword oltre ai tuoi post su come renderlo possibile. Sul retro di questo, è possibile provare per decomprimere il pacchetto docx (è un file zip) e manipolare direttamente i file XML. Non ho idea di come andrà a finire ... ipoteticamente, fatto bene, non è diverso da come se fosse stato fatto manualmente in Word. Ho sperimentato usando un testo di riempimento e manualmente facendo un "Segna tutti" per l'indice su un termine nel documento. Quello che posso trovare è la seguente:

Aggiunge come il primo figlio in ~/[CONTENT_TYPES] .xml:

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

crea la cartella ~/CustomXML -

Nella cartella ~/CustomXML , item1.xml crea:

<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> 

Nella cartella ~/CustomXML, crea 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> 

crea la cartella ~/CustomXML/_rels: Nella cartella ~/CustomXML/_rels, crea 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> 

I ~/docProps cartella cambiato, ma è irrilevante come rigenera word/aggiorna questi valori su ogni apertura/chiusura e non hanno alcuna rilevanza sul contenuto del file.

Fondamentalmente, questo lascia la cartella ~/word. Così, ~ modifiche/parola/styles.xml da aggiungere alla fine uno stile per l'indice, come segue:

<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> 

La w: elementi rsid in ~/parola/settings.xml tutto è cambiato, e onestamente , questi sono sparsi ovunque e non sono sicuro di come funzionano/sono calcolati o se contano troppo.

In ~/word/_rels/document.xml.REL, il seguente è stato aggiunto come figlio del nodo Relazioni:

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

Ultimo e forse più importante, in ~/parola/document.xml, ogni occorrenza del mio mandato per l'indicizzazione ("seduto") è seguita dai seguenti elementi:

<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> 

C'è anche un po 'alla fine dove ho inserito l'indice:

<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> 

Speriamo che questo aiuta. So che è una soluzione complessa, ma è l'unica cosa che riesco a trovare che ti aiuterà e in realtà a farlo in modo automatico. Sconfigge the official, manual way of doing this un po 'e dovrebbe mantenere le caratteristiche di un indice che hai fatto in quel modo. Ti consiglio se lo fai seriamente, utilizzando WinMerge per visualizzare le differenze tra i file (fai clic con il tasto destro e usa Confronta speciali> XML dopo aver aperto due cartelle) e ti auguro buona fortuna. Se si tratta di un one-off, mi piacerebbe solo mordere il proiettile e farlo manualmente. Probabilmente è più veloce e ha meno mal di testa.

Problemi correlati