misc_bb 7 Posted March 8, 2022 Anyone playing around with docx files and trying to update a table of contents via win32com? I've got a working one with Python but our production environment runs on 10.4 only and we're having issues compiling it with P4D. So, i'll just ask if anyone has some similar implementation of this Python code in Delphi? def update_toc(docx_file): word = win32com.client.DispatchEx("Word.Application") doc = word.Documents.Open(docx_file) doc.TablesOfContents(1).Update() doc.Close(SaveChanges=True) word.Quit() thanks in advance for your thoughts and comments. Share this post Link to post
Remy Lebeau 1398 Posted March 8, 2022 (edited) Try something like this: procedure update_toc(const docx_file: string); var word, doc: Variant; begin word := CreateOleObject('Word.Application'); doc := word.Documents.Open(WideString(docx_file)); doc.TablesOfContents.Item(1).Update; doc.Close(-1); word.Quit; end; Edited March 8, 2022 by Remy Lebeau 2 Share this post Link to post
misc_bb 7 Posted March 8, 2022 (edited) Thank you @Remy Lebeau I'll give this a try. wow it does work! I never thought it was possible because in my readings, word needs to open the file in order to update the table of contents. Thanks again! 😉 Edited March 8, 2022 by misc_bb Share this post Link to post
limelect 48 Posted March 9, 2022 @Remy Lebeau what will be the same idea word := CreateOleObject('Word.Application'); for OPEN OFFICE? Share this post Link to post
tgbs 14 Posted March 9, 2022 CreateOleObject('com.sun.star.ServiceManager'); Read here Share this post Link to post