Skip to content

Instantly share code, notes, and snippets.

@rdapaz
Created April 1, 2020 00:40
Show Gist options
  • Save rdapaz/c9ef1724d5cd758015680991d438d493 to your computer and use it in GitHub Desktop.
Save rdapaz/c9ef1724d5cd758015680991d438d493 to your computer and use it in GitHub Desktop.
Increment ID column on a table
import win32com.client as c
wordApp = c.gencache.EnsureDispatch('Word.Application')
wordApp.Visible = True
path = r'<DOC_PATH_HERE>'
doc = wordApp.Documents.Open(path)
for tbl in doc.Tables:
if "ID" in tbl.Cell(1,1).Range.Text: # Or some defining feature on table header
count = 0
for row in range(2, tbl.Rows.Count+1):
count += 1
tbl.Cell(row,1).Range.Text = count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment