python在文本添加超链接_使用python在microsoftword中添加超链接

# How to insert hyperlinks into an existing MS Word document using win32com:

# Use the same call as in the example above to connect to Word:

wordapp = win32com.client.Dispatch("Word.Application")

# Open the input file where you want to insert the hyperlinks:

wordapp.Documents.Open("my_input_file.docx")

# Select the currently active document

doc = wordapp.ActiveDocument

# For my application, I want to replace references to identifiers in another

# document with the general format of "MSS-XXXX", where X is any digit, with

# hyperlinks to local html pages that capture the supporting details...

# First capture the entire document's content as text

docText = doc.Content.text

# Search for all identifiers that match the format criteria in the document:

mss_ids_to_link = re.findall('MSS-[0-9]+', docText)

# Now loop over all t

你可能感兴趣的:(python在文本添加超链接)