durs / node-activex

Node.JS Implementaion of ActiveXObject
MIT License
329 stars 62 forks source link

update docx toc failed in word but succeeded in wps #120

Closed lianyzhou closed 1 year ago

lianyzhou commented 1 year ago

First Thanks to Great job on creating node-activex,this makes more possibility for nodejs application.

Recently I encoutered a requirement of updating docx's table of contents,and I found node-activex.

Currently I cound did it by using WPS(https://www.wps.com/), but when using microsoft word, it report a error.

image

Here's my code ` var winax = require("winax"); var word; let doc = null; try { // word = new winax.Object("KWPS.Application"); word = new winax.Object("Word.Application"); doc = word.documents.open("E:/1.docx") doc.TablesOfContents[1].UpdatePageNumbers(); doc.save(); } catch(e) { console.log('encoutered exception', e); } finally { try { doc && doc.close(); } catch(e){ console.log('doc.close error'); }

try {
    word && word.quit();
} catch(e){
    console.log('word.quit error');
}

try {
    word && winax.release(word);
} catch(e){
    console.log('winax.release error');
}

} `

the word api i found here: https://learn.microsoft.com/zh-tw/dotnet/api/microsoft.office.interop.word.tableofcontents.updatepagenumbers?view=word-pia#microsoft-office-interop-word-tableofcontents-updatepagenumbers

lianyzhou commented 1 year ago

My Computer Environment:

win32 10.0.19044(x64) Windows 10 Home China 21H2 Windows Feature Experience Pack 120.2212.4190.0

nodejs version: v16.14.0 winax version: 3.3.4

lianyzhou commented 1 year ago

here's my docx file 1.docx

lianyzhou commented 1 year ago

console.log(doc.TablesOfContents[1]) and i found there's no UpdatePageNumbers function for word image

durs commented 1 year ago

Hi, doc.TablesOfContents is not array and similar doc.TablesOfContents.Item is not array, so you need to call Item as method: doc.TablesOfContents.Item(1).UpdatePageNumbers()

lianyzhou commented 1 year ago

@durs Thanks a lot, doc.TablesOfContents.Item(1).UpdatePageNumbers() will work