word vba自动化排版-设置标题模板样式、标题、正文、图表、页面、上下标等设置、删除空白行、删除分页符分节符、删除空格等

这篇具有很好参考价值的文章主要介绍了word vba自动化排版-设置标题模板样式、标题、正文、图表、页面、上下标等设置、删除空白行、删除分页符分节符、删除空格等。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

word vba自动化排版-设置标题模板样式、标题、正文、图表、页面、上下标等设置、删除空白行、删除分页符分节符、删除空格等

目录

1.前提

2.思路

3.word中设置

4.效果图

5.经验教训

6.直接上代码


1.前提

        需求:工作中涉及自动识别大量的文字报告(ocr完成),然后对报告进行排版,手动排版效率超级慢,因此探索了一下word vba自动排版

        参考:chatgpt、word vba官网文档、这篇博客csdn、这篇博客知乎、还有上下标的博客不知出处

        注意:不要期望别人都给代码注释好这个参数、这个函数是什么作用什么意思,像CentimetersToPoints、CharacterUnitFirstLineIndent等等,去官网文档查看一下才最有深刻印象。

着重理解官网文档selection、activedocument的关联,以及word 对象之间的关联(主要看对象属性里面有哪些 跳转一下查看),像inlinshape.range.ParagraphFormat嵌入式图片的段落样式设置等等。。。

2.思路

       先了解一下基础语法!

        ①对于标题模板样式、段落文字的样式设置 主要用录制宏来实现,基于此修改代码

        ②对于find、段落、document、selection等的函数参数要去官网查看文档

        ③对于删除分页符等参考的chatgpt,国内的大模型不行

        ④对于上下标,参考的不知出处的博客-感谢

        ⑤设置图表样式 参考官网、博客、chatgpt

        录制宏不是万能的,对于删除分页符、设置图表样式这样的操作,录制宏的代码单独执行不起作用!

        若想精通熟练使用vba进行排版,还是需要去官网了解vba的对象结构,以及函数用法。

        直接上手用,若复杂操作会比较依赖chatgpt,实际上很多参数不知道啥作用,查看官方文档需要较长时间理解。

        代码可以在wps中运行,但是样式有的不尽人意。

3.word中设置

        ①先设置 开发工具:文件->选项->信任中心设置->启用宏

        ②打开 开发工具->vb编辑器->工具->引用->勾选“Microsoft VBScript Regular Expressions 5.5”

4.效果图

        TODO

5.经验教训

        ①对于段落(非图表)参数越多越好,参数之间会互相影响(使用录制宏)

        ②对于图表,参数不一定越多越好,有的参数互相影响,导致效果有问题

6.直接上代码

        涉及:设置标题图片模板样式、标题、正文、图表、页面、上下标等样式、删除空白行、删除分页符分节符、删除空格等文章来源地址https://www.toymoban.com/news/detail-800972.html

Sub 设置标题正文模板样式1()
'
' 设置标题正文模板样式 宏
' 设置2级标题、正文的字体段落、图片样式模板
'
    With ActiveDocument.Styles(wdStyleHeading2).Font
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 22
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Scaling = 100
        .Kerning = 1
        .Animation = wdAnimationNone
        .DisableCharacterSpaceGrid = False
        .EmphasisMark = wdEmphasisMarkNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    With ActiveDocument.Styles(wdStyleHeading2).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
        .WidowControl = False
        .KeepWithNext = False
        .KeepTogether = True
        .PageBreakBefore = True
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .OutlineLevel = wdOutlineLevel2
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    ActiveDocument.Styles(wdStyleHeading2).NoSpaceBetweenParagraphsOfSameStyle = False
    With ActiveDocument.Styles(wdStyleHeading2)
        .AutomaticallyUpdate = False
        .BaseStyle = wdStyleNormal
        .NextParagraphStyle = wdStyleNormal
    End With

    '新建 图片样式 判断是否存在
    On Error Resume Next  ' 暂时禁用错误处理
    styleExists = Not (ActiveDocument.Styles("图片样式") Is Nothing)
    On Error GoTo 0       ' 恢复正常的错误处理

    If Not styleExists Then
        ActiveDocument.Styles.Add Name:="图片样式", Type:=wdStyleTypeParagraph
    End If
    
    ActiveDocument.Styles("图片样式").AutomaticallyUpdate = True
    With ActiveDocument.Styles("图片样式").Font
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .NameOther = "Times New Roman"
        .Name = "Times New Roman"
        .Size = 10.5
        .Bold = False
        .Italic = False
        .Underline = wdUnderlineNone
        .UnderlineColor = wdColorAutomatic
        .StrikeThrough = False
        .DoubleStrikeThrough = False
        .Outline = False
        .Emboss = False
        .Shadow = False
        .Hidden = False
        .SmallCaps = False
        .AllCaps = False
        .Color = wdColorAutomatic
        .Engrave = False
        .Superscript = False
        .Subscript = False
        .Scaling = 100
        .Kerning = 1
        .Animation = wdAnimationNone
        .DisableCharacterSpaceGrid = False
        .EmphasisMark = wdEmphasisMarkNone
        .Ligatures = wdLigaturesNone
        .NumberSpacing = wdNumberSpacingDefault
        .NumberForm = wdNumberFormDefault
        .StylisticSet = wdStylisticSetDefault
        .ContextualAlternates = 0
    End With
    With ActiveDocument.Styles("图片样式").ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphCenter
        .WidowControl = False
        .KeepWithNext = True
        .KeepTogether = True
        .PageBreakBefore = True
        .NoLineNumber = False
        .Hyphenation = True
        .FirstLineIndent = CentimetersToPoints(0)
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .OutlineLevel = wdOutlineLevelBodyText
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
        .TextboxTightWrap = wdTightNone
        .CollapsedByDefault = False
        .AutoAdjustRightIndent = True
        .DisableLineHeightGrid = False
        .FarEastLineBreakControl = True
        .WordWrap = True
        .HangingPunctuation = True
        .HalfWidthPunctuationOnTopOfLine = False
        .AddSpaceBetweenFarEastAndAlpha = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    ActiveDocument.Styles("图片样式").NoSpaceBetweenParagraphsOfSameStyle = False
    ActiveDocument.Styles("图片样式").ParagraphFormat.TabStops.ClearAll
    With ActiveDocument.Styles("图片样式").ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = wdColorAutomatic
        End With
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        With .Borders
            .DistanceFromTop = 1
            .DistanceFromLeft = 4
            .DistanceFromBottom = 1
            .DistanceFromRight = 4
            .Shadow = False
        End With
    End With
    ActiveDocument.Styles("图片样式").Frame.Delete
    
    MsgBox "标题正文模板样式设置完成"
End Sub


Sub 设置页面参数2()
'
'设置初始化:取消所有样式、设置页边距、设置纸张大小、页眉页脚边距、每页行数、每行字数、设置所有段落为正文样式
'
    Selection.WholeStory
    Selection.ClearFormatting
    Selection.Range.HighlightColorIndex = wdNoHighlight
    
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(2.54)
        .BottomMargin = CentimetersToPoints(2.54)
        .LeftMargin = CentimetersToPoints(3.17)
        .RightMargin = CentimetersToPoints(3.17)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.5)
        .FooterDistance = CentimetersToPoints(1.75)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
        .CharsLine = 39
        .LinesPage = 44
        .LayoutMode = wdLayoutModeGrid
    End With
    ' 设置正文样式
    Selection.Style = ActiveDocument.Styles(wdStyleNormal)
    
    Selection.HomeKey Unit:=wdStory
    MsgBox "页面参数样式设置完成"

End Sub


Sub 删除空白行3()
'
'先执行删除空白行(不可等设置完样式后再执行),再将全文所有空格删除
'
    Dim para As Paragraph
    Dim isBlank As Boolean
    
    For Each para In ActiveDocument.Paragraphs
        isBlank = True
        If Len(para.Range.text) <> 1 Then
            isBlank = False
        End If
        
        If para.Range.Information(wdWithInTable) = False Then
            If isBlank Then
                para.Range.Delete
            End If
        End If
    Next
    ActiveDocument.Content.Find.Execute FindText:=" ", ReplaceWith:="", Replace:=wdReplaceAll
    MsgBox "已删除所有空白行(非表格内)、空格"
End Sub

Sub 删除分页符4_1()
'chatgpt生成 需要去了解While .Execute用法、Collapse 等
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Selection.HomeKey Unit:=wdStory
    Dim rng As Range
    Set rng = ActiveDocument.Content

    Dim regEx As Object
    Set regEx = CreateObject("VBScript.RegExp")
    With regEx
        .Global = True
        .pattern = "\d+"
    End With
    With rng.Find
        .ClearFormatting
        .text = "^m"
        .Forward = True
        .Wrap = wdFindStop

        While .Execute
            Dim lineText As String
            lineText = rng.Paragraphs(1).Range.text

            If regEx.test(lineText) Then
                Dim matches As Object
                Set matches = regEx.Execute(lineText)
                If matches.Count > 0 Then
                    rng.Paragraphs(1).Range.Delete
                End If
            End If

            rng.Collapse Direction:=wdCollapseEnd
            rng.MoveStart Unit:=wdCharacter, Count:=1
        Wend
    End With
    
End Sub

Sub 删除分节符4_2()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Selection.HomeKey Unit:=wdStory
    Dim rng As Range
    Set rng = ActiveDocument.Content

    Dim regEx As Object
    Set regEx = CreateObject("VBScript.RegExp")
    With regEx
        .Global = True
        .pattern = "\d+"
    End With

    With rng.Find
        .ClearFormatting
        .text = "^b"
        .Forward = True
        .Wrap = wdFindStop

        While .Execute

            Dim lineText As String
            lineText = rng.Paragraphs(1).Range.text

            If regEx.test(lineText) Then
                Dim matches As Object
                Set matches = regEx.Execute(lineText)
                If matches.Count > 0 Then
                    rng.Paragraphs(1).Range.Delete
                End If
            End If

            rng.Collapse Direction:=wdCollapseEnd
            rng.MoveStart Unit:=wdCharacter, Count:=1
        Wend
    End With
    
    ActiveDocument.Content.Find.Execute FindText:="^b", ReplaceWith:="", Replace:=wdReplaceAll '删除分节符
    ActiveDocument.Content.Find.Execute FindText:="^m", ReplaceWith:="", Replace:=wdReplaceAll '删除分页符
    
End Sub

Sub 删除分页符分节符4()
    Call 删除分页符4_1
    Call 删除分节符4_2
    MsgBox "已删除所有分页符分节符"
End Sub


Sub 遍历设置各级段落样式5()
'
'遍历每个段落 逐段落进行标题匹配设置样式
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Selection.HomeKey Unit:=wdStory
    Dim t2_reg, t3_reg, t4_reg, t5_reg, t6_reg, t7_reg, cankao_reg
        
    Set t2_reg = CreateObject("vbscript.regexp")
    t2_reg.pattern = "^(第[一二三四五六七八九十 ]+篇[^\r]*)\r"
    Set t3_reg = CreateObject("vbscript.regexp")
    
    Dim para As Paragraph
    Dim isSearched As Boolean
    Dim pos As Long
    For Each para In ActiveDocument.Paragraphs
        '用if-elseif更好-不想改了
        isSearched = False
        If t2_reg.test(para.Range.text) And Not isSearched Then
            isSearched = True
            para.Style = ActiveDocument.Styles(wdStyleHeading2)
            pos = InStr(para.Range.text, "篇") + 1
            para.Range.Characters(pos).InsertBefore " " '此段落一定有篇
        End If
        
    Next
    Selection.HomeKey Unit:=wdStory
    MsgBox "遍历设置各级段落样式完成"

End Sub

Sub 设置各级标题样式5()
'不推荐-慢
'采用正则匹配,然后查找设置对应的段落格式
'https://devbox.cn/p/Zai_vba_Zhong_di_460e0cc1.html(非对象不使用set,需要提前Dim声明,对象需要set,可不Dim声明)
'可简化成1个函数,传参遍历执行-但不想!
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim t2_reg, t3_reg, t4_reg, t5_reg, t6_reg, t7_reg, strA$  '最后1个$ 只对strA有效
    strA = ActiveDocument.Content.text
    Set t2_reg = CreateObject("vbscript.regexp")

    '二级标题
    Selection.HomeKey Unit:=wdStory
    t2_reg.pattern = "\r(第[一二三四五六七八九十 ]+篇[^\r]*)\r"
    t2_reg.Global = True
    Set t2_titles = t2_reg.Execute(strA)
    
    For Each t2_title In t2_titles
        With Selection.Find
            .ClearFormatting
            .text = t2_title.SubMatches(0)
            .Execute Forward:=True
        End With
    
        Selection.Style = ActiveDocument.Styles(wdStyleHeading2)
    
        Selection.HomeKey Unit:=wdStory
    Next
    MsgBox "标题正文样式设置完成"
End Sub


Sub 设置图表样式6()
'
'设置图表样式
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim mytable As Table
    For Each mytable In ActiveDocument.Tables
        With mytable
            .TopPadding = PixelsToPoints(0, True)
            .BottomPadding = PixelsToPoints(0, True)
            .LeftPadding = PixelsToPoints(0, True)
            .RightPadding = PixelsToPoints(0, True)
            .Spacing = PixelsToPoints(0, True)
            .AllowPageBreaks = True
            .AllowAutoFit = True
            With .Rows
                .WrapAroundText = False
                .Alignment = wdAlignRowCenter
                .AllowBreakAcrossPages = False
                .HeightRule = wdRowHeightExactly
                .Height = CentimetersToPoints(0)
                .LeftIndent = CentimetersToPoints(0)
            End With
            
            With .Range
                With .Font
                    .Name = "宋体"
                    .Name = "Times New Roman"
                    .Color = wdColorAutomatic
                    .Size = 7.5
                    .Kerning = 0
                    .DisableCharacterSpaceGrid = True
                End With
                
                With .ParagraphFormat
                    .CharacterUnitFirstLineIndent = 0
                    .FirstLineIndent = CentimetersToPoints(0)
                    .LineSpacingRule = wdLineSpaceSingle
                    .Alignment = wdAlignParagraphCenter
                    .AutoAdjustRightIndent = False
                    .DisableLineHeightGrid = True
                    
                    .LeftIndent = CentimetersToPoints(0)
                    .RightIndent = CentimetersToPoints(0)
                    .FirstLineIndent = CentimetersToPoints(0)
                    .CharacterUnitLeftIndent = 0
                    .CharacterUnitRightIndent = 0
                    .CharacterUnitFirstLineIndent = 0
                End With
                .Cells.VerticalAlignment = wdCellAlignVerticalCenter
            End With

            .PreferredWidthType = wdPreferredWidthPoints
            .PreferredWidth = CentimetersToPoints(14.5)
            With .Borders
                .InsideLineStyle = wdLineStyleSingle
                .OutsideLineStyle = wdLineStyleSingle
                .InsideLineWidth = wdLineWidth025pt
                .OutsideLineWidth = wdLineWidth025pt
                .InsideColor = wdColorAutomatic
                .OutsideColor = wdColorAutomatic
            End With
            
        End With
    Next
    Selection.HomeKey Unit:=wdStory

    Dim ishape As InlineShape
    For Each ishape In ActiveDocument.InlineShapes
        With ishape
            If .Type = wdInlineShapePicture Then
                .LockAspectRatio = msoTrue
                .Width = CentimetersToPoints(14.5)
            End If
        End With
        ishape.Range.Style = ActiveDocument.Styles("图片样式")

    Next
    Dim sh As Shape
    For Each sh In ActiveDocument.Shapes
        With sh
            If .Type = msoPicture Then
                .LockAspectRatio = msoTrue
                .Width = CentimetersToPoints(14.5)
            End If
        End With

        With Selection.ParagraphFormat
            .LeftIndent = CentimetersToPoints(0)
            .RightIndent = CentimetersToPoints(0)
            .FirstLineIndent = CentimetersToPoints(0)
        End With
    Next
    
    Selection.HomeKey Unit:=wdStory
    
    MsgBox "图表样式设置完成"

End Sub

Private Sub SetSuperscriptAndSubscript(ByVal PrefixChr As String, ByVal SetChr As String, Optional ByVal PostChr As String, Optional ByVal SuperscriptMode As Boolean = True)
   '程序功能:设置文档中特定字符为上标或下标。
   '参数说明:
   'PrefixChr:必选参数,要设置为上、下标字符之前的字符;
   'SetChr:必选参数,要设置为上、下标的字符;
   'PostChr:必选,但可赋空字符串,若为了界定整个替换符号而包含的后缀,防止误替换,可加此参数
   'SuperscriptMode:可选参数,设置为 True 表示将 SetChr 设置为上标,设置为 False 表示将 SetChr 设置为下标,默认为 True。

   Selection.Start = ActiveDocument.Paragraphs(1).Range.Start
   Selection.Collapse wdCollapseStart
   With Selection.Find
       .ClearFormatting
       .MatchCase = False
       .Replacement.ClearFormatting
       .text = PrefixChr & SetChr & PostChr
       .Replacement.text = .text
       If SuperscriptMode Then
           .Replacement.Font.Superscript = True
       Else
           .Replacement.Font.Subscript = True
       End If
       .Execute Replace:=wdReplaceAll
       .ClearFormatting
       .Replacement.ClearFormatting
       .text = PrefixChr
       If SuperscriptMode Then
           .Font.Superscript = True
       Else
           .Font.Subscript = True
       End If
       .Replacement.text = .text
       If SuperscriptMode Then
           .Replacement.Font.Superscript = False
       Else
           .Replacement.Font.Subscript = False
       End If
       .Execute Replace:=wdReplaceAll
       If Len(PostChr) > 0 Then
           .ClearFormatting
           .Replacement.ClearFormatting
           .text = PostChr
           If SuperscriptMode Then
               .Font.Superscript = True
           Else
               .Font.Subscript = True
           End If
           .Replacement.text = .text
           If SuperscriptMode Then
               .Replacement.Font.Superscript = False
           Else
               .Replacement.Font.Subscript = False
           End If
           .Execute Replace:=wdReplaceAll
       End If
   End With
End Sub


Sub 执行上下标7()
'
'依靠SetSuperscriptAndSubscript来实现
'
    Call SetSuperscriptAndSubscript("O", "+", "", True)
    Call SetSuperscriptAndSubscript("O", "-", "", True)
    
    Call SetSuperscriptAndSubscript("H", "2", "O", False)
    Call SetSuperscriptAndSubscript("TiO", "2", "", False)
    
    MsgBox "设置上下标完成"
End Sub

Sub 数字智能自动排版流程_遍历段落()
    MsgBox "这种遍历更快更好-磊磊"
    Call 设置标题正文模板样式1
    Call 设置页面参数2
    Call 删除空白行3
    Call 删除分页符分节符4
    Call 遍历设置各级段落样式5
    Call 设置图表样式6
    Call 执行上下标7
    MsgBox "已全部设置完成-磊磊"
End Sub

到了这里,关于word vba自动化排版-设置标题模板样式、标题、正文、图表、页面、上下标等设置、删除空白行、删除分页符分节符、删除空格等的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Python办公自动化之Word文档自动化:全网最全,看这一篇就够了

    目录 一、环境安装 1、升级pip 2、python-docx 3、win32com 4、mailmerge 5、matplotlib 二、Python-docx 新建文档 三、Python-docx 编辑已存在文档 四、win32com 将 doc 转为 docx 五、win32com 操作 word 1、打开新的word文档并添加内容 2、打开已存在word文档并添加内容 3、转换word为pdf 六、Python-docx 操作

    2024年02月01日
    浏览(44)
  • python办公自动化(6)——读取word文档

    因为我们要进行文件相关的操作,所以需要在一开始使用import导入Python内置的os模块。 我们需要先获取该文件夹下所有的答题卡列表,再使用for循环遍历文件夹中所有学生的答题卡,以便之后逐个读取信息。 完成了第一个步骤,接下来,我们就需要在for循环里,依次获取每位

    2023年04月08日
    浏览(45)
  • Word、Excel、PPT题库——“办公自动化”

    小雅兰期末加油冲冲冲!!! 1. 【单选题】下列文件扩展名,不属于Word模板文件的是( A )。 A. .DOCX B. .DOTM C. .DOTX D. .DOT 本题的考查点是word基本知识的了解。     .DOCX:word文档。     .DOTM:启用宏的word模板。     .DOTX:word模板。     .DOT:word 97-2003模板。     故本题答案为

    2024年02月07日
    浏览(55)
  • python自动化办公——读取PPT写入word表格

    📖由于我们知识图谱课程需要将课堂小组汇报的PPT总结成word文档,而我觉得一页一页复制PPT中的内容比较麻烦,所以直接安排:读PPT写word 🚗需要操作PPT幻灯片和word文档,所以需要导入docx 和pptx两个包 这里我的docx使用的是0.2.4版本 pptx使用的是0.6.21版本供参考 引入os、ppt

    2024年02月11日
    浏览(30)
  • Python操作Word:轻松实现文档的创建、编辑与自动化处理

    引言: 在日常工作和学习中,我们经常需要使用Microsoft Word来创建、编辑和处理文档。然而,手动操作Word可能会耗费大量的时间和精力。为了提高工作效率,我们可以使用Python编程语言来操作Word文档,实现文档的自动化处理。本文将详细介绍如何使用Python操作Word,包括创建

    2024年01月21日
    浏览(40)
  • Python自动化小技巧21——实现PDF转word功能(程序制作)

    案例背景 为什么这个年代PDF转word,某wps居然还要收费.....很多软件都可以实现这个功能,但是效果都有好有坏,而且有的还付费,很麻烦。 那就用python实现这个功能吧,然后把代码打包为.exe的程序,这样随便在哪个电脑上都能运行,给那些没有python环境的人一个便利。 代码

    2024年02月11日
    浏览(39)
  • python自动化办公——定制化读取Excel数据并写入到word表格

    最近到了毕业设计答辩的时候,老师让我帮毕业生写一段毕业设计的功能就是提供一个 学士学位授予申请表 ,根据定制化需求,编写定制化代码。 docx格式的word如下图。 再提供一个Excel表格,要求可以直接读取表格里的对应内容,填入到word表格里的对应位置。表格是我自己

    2024年02月10日
    浏览(43)
  • 怎么从休学证明中取出休学原因(python自动化办公,涉及word和excel)

    本代码偏向处理高校教务处的工作 休学或请假模板如下: 需求说明: 代码如下: 重要知识点补充

    2024年02月07日
    浏览(43)
  • 接口自动化测试实践指导(下):接口自动化测试断言设置思路

    作者 : 石臻臻 , CSDN博客之星Top5 、 Kafka Contributor 、 nacos Contributor 、 华为云 MVP , 腾讯云TVP , 滴滴Kafka技术专家 、 KnowStreaming 。 KnowStreaming 是滴滴开源的Kafka运维管控平台, 有兴趣一起参与参与开发的同学,但是怕自己能力不够的同学,可以联系我,当你导师带你参与开源! 。 在

    2024年01月18日
    浏览(56)
  • python从小白到大师-第一章Python应用(八)应用领域与常见包-自动化办公word

    目录 一.python-docx 二.pypiwin32 Python-docx是一个用于创建、修改和读取Microsoft Word文件(.docx)的Python库。它提供了一组丰富的功能,使开发人员能够使用Python生成自定义的Word文档。 以下是python-docx库的一些主要特点和功能: 创建和编辑Word文档:可以使用python-docx库创建新的Wor

    2024年02月21日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包