程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Copy and paste Python win32com between two or more words in Win32

編輯:Python
from win32com.client import Dispatch
import time
myWord = Dispatch('Word.Application')
myWord.Visible = 1 # comment out for production
url = 'http://127.0.0.1:8000/t/%E6%96%B0%E9%97%BB/1.html'
# use word Open web pages to maximize formatting 
myWord.Documents.Open(url) # open file
doc = myWord.ActiveDocument
rngPage = doc.Bookmarks("\Page").Range
page_count = doc.ActiveWindow.Panes(1).Pages.Count
print('pagecount', page_count)
# time.sleep(1000)
# Future generations 
myWord.Selection.WholeStory()
# Copy 
myWord.Selection.Copy()
doc_add = myWord.Documents.Open(r"C:\Users\Administrator\Documents\1.docx")
wdRange = doc_add.Content
print(doc.Name)
# Activate doc_add
myWord.Documents(doc_add).Activate()
doc = myWord.ActiveDocument
print(doc.Name)
# Copy paste twice 
myWord.Selection.Paste()
myWord.Selection.Paste()
myWord.ActiveDocument.SaveAs('172.docx',16)
myWord.Quit() # close Word.Application

Reference resources
Official documents
https://docs.microsoft.com/en-us/office/vba/api/word.words
https://stackoverflow.com/questions/15274601/opening-a-ms-word-file-in-pywin32
https://www.cnblogs.com/zhuminghui/p/11765401.html


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved