Created
April 1, 2020 00:40
-
-
Save rdapaz/c9ef1724d5cd758015680991d438d493 to your computer and use it in GitHub Desktop.
Increment ID column on a table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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