import win32com.client as win32
from time import sleep
import os
def writeFile(myword, doc, rng, filesize, filepath):
#myword.Open(filepath)
#rng = doc.Range(0,0)
rng.InsertAfter('add by writerFile\r\n')
while (os.path.getsize(filepath) <= filesize):
for i in RANGE:
rng.InsertAfter('hello this is word file, Smart Classifier
test data' + str(i) + "\r\n")
rng.InsertAfter('welcome to CDC, this file is created by Icy. ' + str(i) + "\r\n")
mydoc.SaveAs(filepath)
doc.Close()
myword.Application.Quit()
if __name__=='__main__':
RANGE = range(1,3000)
app = 'word'
filepath = 'C:\\Temp\\2.docx'
filesize = 555000
myapp = win32.Dispatch('%s.Application' %app)
myapp.Visible = True
mydoc = myapp.documents.Add()
sleep(1)
rng = mydoc.Range(0,0)
rng.InsertAfter('Python-to-%s Test\r\n\r\n' %app)
mydoc.SaveAs(filepath)
writeFile(myapp, mydoc, rng, filesize, 'C:\\Temp\\2.docx')