


# Purpose : To update the Table contents present in file
#Ms word how to update table of contents code#
Also I figured out, since there in not much documentation available on the API's used for python/win32 (except the MSDN library), the one way which i thought to get used to these APIs is to understand the VB code (mostly its present MSDN ) and try to make a corresponding similar code for python-win32 too. While doing this, I learned how to clear content of a table (specific row and column), how to add a row, get the count of columns and rows in a word table et al. I'm going to share the code which I have written to fix it. Please ignore the commented out sections (I was also trying to make the stuff work) # this one deletes the whole table (which is not needed)ĭoc.SaveAs(IP_Directory_Dest + "\\" + name) Print table.Cell(Row =1, Column = 1).Range.Text # to get the content of Row # 1, Column # 1 of table

# print the row 1 of TABLE # 1 - after Deleting the first ROW -> for checking

# again count the number of rows in table # print the row 1 of TABLE # 1 - for checking Print ('Number of Columns in TABLE',numCols) Print ('Number of Rows in TABLE',numRows) # = "This is the string to add to the document." Python function for clearing the table contents is pasted herein with Is there something that I'm missing ? Any suggestions are welcome. (Also had a look How to read contents of an Table in MS-Word file Using Python? )īut on doing the above steps, the table row isn't deleted (neither the cell is deleted). I even looked at the MSDN library ( ) and found that Delete could help me in this, something like this. I'm trying to update a microsoft word - 2010 table by deleting its contents (except the first row contents) using python and win32com client component.
