遍历Word中的页面并查找包含图像的页面 [英] Iterate through pages in Word and find pages contains image

查看:124
本文介绍了遍历Word中的页面并查找包含图像的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历word文档中的每个页面,检查该页面是否包含图像,然后对该页面进行一些操作(设置页面边距并插入一个分隔符).

I want to iterate though every page in a word document, check if that page contains an images or not, and do something about that page (Set page margin and insert a break).

For Each Page in Document.Pages
   If Page.ContainsImage Then
      Page.TopMargin = 0
      DoOtherStuff
   End If
Next

推荐答案

Document具有表示所有Shape的Shapes集合.每个Shape都有一个Anchor,通过它可以访问该形状页面的TopMargin和其他属性:

A Document has a Shapes Collection representing all the Shapes. Each Shape has an Anchor, using which we can get to the TopMargin, and other properties, of the shape's page:

Sub JiggleAllShapes()
    Dim shp As Shape

    For Each shp In ActiveDocument.Shapes
        shp.Anchor.Paragraphs(1).Range.PageSetup.TopMargin = 0
    Next shp
End Sub

我们可以从Anchor获取页码:

shp.Anchor.Information(wdActiveEndPageNumber)

有一个Pages集合,但是它不像IMO有用:

There is a Pages Collection but it is not as useful IMO:

Sub WhatAboutPages()
    Dim pge As Page

    For Each pge In ActiveDocument.ActiveWindow.Panes(1).Pages
        'Debug.Print pge.NothingUsefulHere
    Next pge
End Sub

使用这种方法,您必须深入研究Rectangles集合并使用RectangleType来尝试确定当前Rectangle是否是图像.

With this approach you would have to delve into the Rectangles collection and use RectangleType to try to determine if the current Rectangle is an image.

这篇关于遍历Word中的页面并查找包含图像的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆