更新目录,按range更新
Sub mulu1() ActiveDocument.Fields(1).Update Selection.SetRange Start:=177, End:=552 Selection.Font.Name = "黑体" With Selection.Font .Size = 20 .SizeBi = 20 .TextColor = RGB(13, 146, 163) End With With Selection.ParagraphFormat .LineSpacingRule = wdLineSpaceExactly .LineSpacing = 8 .LineSpacing = 80 .LineSpacingRule = wdLineSpaceExactly .LineSpacing = 80 .DisableLineHeightGrid = 0 .ReadingOrder = wdReadingOrderLtr .AutoAdjustRightIndent = -1 .WidowControl = 0 .KeepWithNext = 0 .KeepTogether = 0 .PageBreakBefore = 0 .FarEastLineBreakControl = -1 .WordWrap = -1 .HangingPunctuation = -1 .HalfWidthPunctuationOnTopOfLine = 0 .AddSpaceBetweenFarEastAndAlpha = -1 .AddSpaceBetweenFarEastAndDigit = -1 .BaseLineAlignment = wdBaselineAlignAuto End With ActiveWindow.ActivePane.VerticalPercentScrolled = 14 RecentFiles.Add Document:=ThisDocument.FullName, ReadOnly:=False ActiveDocument.Save End Sub
更新目录,按照区域选择对象进行更新(Python代码,win32com)
word = Dispatch('Word.Application') word.Visible = 0 # 后台运行 word.DisplayAlerts = 0 my_docx = word.Documents.Open(docx_path) for f in my_docx.Fields: f.Update() f.Select() w = word.Selection w.Font.Name = "黑体" w.Font.Size = 20 w.Font.SizeBi = 20 w.Font.TextColor = RGB(13, 146, 163) w.ParagraphFormat.LineSpacingRule = 4 w.ParagraphFormat.LineSpacing = 9 w.ParagraphFormat.LineSpacing = 90 my_docx.Save() if not preview: my_docx.PrintOut() my_docx.Close() # 关闭 word 文档 # word.Quit() # 关闭 office