(Solved) – How to convert MS-WORD table to HTML in VBA/Python

(solved)-–-how-to-convert-ms-word-table-to-html-in-vba/python

I am currently extracting comments and its associated text from MS-Word document.
Sometimes comments is placed on MS-WORD table which I want to convert into HTML table.

SET osht = Activesheet
For n = 1 To nCount
With osht.
    'Commented text
    .Range("A"&n).value = = oDoc.Comments(n).Scope
    'The comment itself
    .Range("B"&n).value = oDoc.Comments(n).Range.Text
    'The comment author
    .Range("A"&n).value = oDoc.Comments(n).Author
End With
Next n

I am facing issue how to identify if comment scope is not a text but a MS-WORD table and then convert it into HTML

Currently MS WORD table is extracted as below in text form

Head1
Head2
Head3

Cell1CEll2Cell3
Cell4CEll5Cell6

Is there any way to identify commented text if a table and to convert it as HTML

Even solution in python will work using WIN32com library

I have tried python as well :

word_app = win32.gencache.EnsureDispatch('Word.Application')
word_app.Visible = False
word_doc = word_app.Documents.Open(Path)
word_doc.Activate()
active_doc = word_app.ActiveDocument
comment_lst = []
for comment in active_doc.Comments:
    comment_lst.append({'commented_text': comment.Scope.Text,
                          'comment': comment.Range.Text})

But I didn’t find any solution in Python as well.

Leave a Reply

Your email address will not be published. Required fields are marked *