|
楼主 |
发表于 2014-4-21 21:57
|
显示全部楼层
本帖最后由 loquat 于 2014-4-21 22:01 编辑
1.简单的从文档属性中获取页数的代码。但是本代码不可靠,因为文档属性是可读写的。
Function GetPagesCount(flPath As String) As Integer
Dim fso As Object, fl As Object, shl As Shell32.Shell
Dim fdPath$, flName$, i&, shfd As Shell32.Folder
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.GetFile(flPath)
fdPath = fl.ParentFolder.Path
flName = fl.Name
Set shl = New Shell
Set shfd = shl.NameSpace(fdPath)
For i = 0 To 300
If Left(shfd.GetDetailsOf(0, i), 1) = "页" Then 'XP中为"页数",Win7中为"页码范围",所有直接查找"页"
GetPagesCount = shfd.GetDetailsOf(shfd.Items.Item(flName), i)
Exit Function
End If
Next i
End Function
2.可靠的方法为:2007以及以上版本的文件,用Open XML SDK打开文件之后读ExtendedFilePropertiesPart.Properties.Pages属性
2003版本的文件,可以用复合文档API StgOpenStorage和IPropertySetStorage读Page Count属性 |
|