标签:
import win32com from win32com.client import Dispatch,constants w = win32com.client.Dispatch(‘Word.Application‘) w.Visible = 0 w.DisplayAlerts = 0 doc = w.Documents.Open(FileName = r‘C:\Users\jack\Desktop\test\课文.rtf‘) ##par = doc.Range(doc.Content.Start,doc.Content.End).Select par = doc.Range(doc.Content.Start,doc.Content.End) ##n = 0 ##for each in w.ActiveDocument.Paragraphs: ## if each.Words.Count == 0: ## each.Range.Delete() ## n += 1 ##print("删除空行共:" + n + "行") ##doc.Paragraphs(1).Range.Delete() ##doc.Paragraphs(2).Range.Delete() ##doc.Paragraphs(3).Range.Delete() ##doc.Paragraphs(4).Range.Delete() w.ActiveDocument.Select() w.Selection.ClearFormatting() ##par.ParagraphFormat.Reset() ##par.Font.Name = "微软雅黑" ##par.Font.Size = "14" ##par1 = doc.Paragraphs(1).Range ##par2 = doc.Paragraphs(2).Range ##par1.Font.Size = "36" ##par2.Font.Size = "24" ##par1.ParagraphFormat.Alignment = 1 ##par2.ParagraphFormat.Alignment = 1 print("ok") doc.Close() w.Quit
标签:
原文地址:http://www.cnblogs.com/Jacklovely/p/5747869.html