zoukankan      html  css  js  c++  java
  • word_宏示例

    参考:https://jingyan.baidu.com/article/870c6fc3326588b03fe4beeb.html

    内容自适应

    Application.Browser.Target = wdBrowseTable
    
      For i = 1 To ActiveDocument.Tables.Count
    
      ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格
    
      ActiveDocument.Tables(i).AutoFitBehavior (wdAutoFitWindow) '根据窗口自动调整表格
    
      ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '水平居中
    
      ActiveDocument.Tables(i).Range.ParagraphFormat.Alignment = wdCellAlignVerticalCenter '垂直居中
    
      Next i
    

    表格修改(清除表格内容)

    Sub www()
    '
    ' www 宏
    '
    '
       Dim oDoc As Document
       Dim oTable As Table
       Dim cellLoop As Cell
       Set oDoc = Documents.Open("F:lili范式.docx")
       Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
       For Each oTable In oDoc.Tables
           RowNum = oTable.Rows.Count
           Column = oTable.Columns.Count
           If Column >= 5 Then
                For i = 1 To RowNum
                        oString = oTable.Cell(i, 4).Range.Text
                        If InStr(1, oString, "日期") = 1 Then
                             oTable.Cell(i, 5).Select
                             Selection.Delete
                        End If
                 Next
            End If
       Next
       MsgBox "Finished!"
    End Sub
    

    表格修改(修改表格内容)

    Sub www()
    '
    ' www 宏
    '
    '
       Dim oDoc As Document
       Dim oTable As Table
       Dim cellLoop As Cell
       Set oDoc = Documents.Open("D:Users说明书.docx")
       Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
       For Each oTable In oDoc.Tables
           RowNum = oTable.Rows.Count
           Column = oTable.Columns.Count
           If Column >= 5 Then
                For i = 1 To RowNum
                        oString = oTable.Cell(i, 4).Range.Text
                        If InStr(1, oString, "日期") = 1 Then
                             oTable.Cell(i, 4).Select
                             Selection.TypeText Text:="DATE"
                             oTable.Cell(i, 5).Select
                             Selection.TypeText Text:="7"
                        End If
                        If InStr(1, oString, "字符串") = 1 Then
                             oTable.Cell(i, 4).Select
                             Selection.TypeText Text:="VARCHAR2"
                        End If
                        If InStr(1, oString, "整数") = 1 Then
                             oTable.Cell(i, 4).Select
                             Selection.TypeText Text:="NUMBER"
                        End If
                        If InStr(1, oString, "小数") = 1 Then
                             oTable.Cell(i, 4).Select
                             Selection.TypeText Text:="FLOAT"
                        End If
                        
                 Next
            End If
       Next
       MsgBox "Finished!"
    End Sub
    

    比较表格中某列的值

    Sub www()
    '
    ' www 宏
    '
    '
       Dim oDoc As Document
       Dim oTable As Table
       Dim cellLoop As Cell
       Set oDoc = Documents.Open("F:work二审详细设计参考文档30个单位规范信息资源库docx办公厅标准信息资源目录.docx")
       Dim RowNum As Long, ColumnNum As Long, i As Long, oString As String
       Dim Ostr2, Ostr3 As String
       Ostr2 = "NULL"
       Ostr3 = "NUL"
       For Each oTable In oDoc.Tables
           RowNum = oTable.Rows.Count
           Column = oTable.Columns.Count
           If Column = 4 Then
                For i = 1 To RowNum
                        For j = 1 To Column
                            oString = oTable.Cell(i, j).Range.Text
                            If InStr(1, oString, "是否开放") = 1 Then
                                oStr = oTable.Cell(i, j).Next.Range.Text
                                If InStr(1, oStr, "否") = 1 Then
                                    Ostr2 = "NO"
                                End If
                                If InStr(1, oStr, "是") = 1 Then
                                    Ostr3 = "YES"
                                End If
                             'Selection.Delete
                            End If
                        Next
                 Next
            End If
       Next
       MsgBox ("Ostr2:" + Ostr2)
       MsgBox ("Ostr3:" + Ostr3)
       MsgBox "Finished!"
    End Sub
    
  • 相关阅读:
    错误:The columns and the margins do not fit the page width.
    jasperreport使用动态jason数据源
    DynamicReport使用XML数据源+ireport的.jxml文件作为模板
    Report bands中文版
    iReport 使用json 数据源
    bat设置java环境变量
    解决DynamicReports中含有中文pdf版本不显示
    vba实现excel二级联动多选功能
    打字游戏 C语言
    fpga 任意分频 奇偶数 分频
  • 原文地址:https://www.cnblogs.com/fmgao-technology/p/10304564.html
Copyright © 2011-2022 走看看