Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我有一个词,博士。我想获得word文档每页的字数?_Php_Ms Word - Fatal编程技术网

Php 我有一个词,博士。我想获得word文档每页的字数?

Php 我有一个词,博士。我想获得word文档每页的字数?,php,ms-word,Php,Ms Word,我只能找到每行的解决方案,但找不到分页符;也困惑了很多。 对于docx,也无法找到确切的字数 }为此实现自己的代码听起来不是个好主意。我建议使用外部库,例如。它应该允许您将文件转换为纯文本。然后,您可以从中提取字数 此外,像这样的外部库还增加了对多种文件格式的支持,而不限制您使用Word 97-2003。解压.doc或.docx文件时,您将获得文件夹。在word子文件夹中查找document.xml文件。您将获得具有xml语法的整个文档。按页面xml语法拆分字符串,然后使用。下面是一段基本的V

我只能找到每行的解决方案,但找不到分页符;也困惑了很多。 对于docx,也无法找到确切的字数


}为此实现自己的代码听起来不是个好主意。我建议使用外部库,例如。它应该允许您将文件转换为纯文本。然后,您可以从中提取字数


此外,像这样的外部库还增加了对多种文件格式的支持,而不限制您使用Word 97-2003。

解压.doc或.docx文件时,您将获得文件夹。在word子文件夹中查找document.xml文件。您将获得具有xml语法的整个文档。按页面xml语法拆分字符串,然后使用。

下面是一段基本的VB.NET代码,它计算每页的字数,但请注意,这取决于单词认为是什么单词,而不一定是用户认为是什么单词。根据我的经验,你需要正确地分析单词的行为,它解释了什么,然后建立你的逻辑,以确保你得到你需要的结果。它不是PHP,但它可以完成这项工作,并且可以成为您的起点

Structure WordsPerPage
    Public pagenum As String
    Public count As Long
End Structure

Public Sub CountWordsPerPage(doc As Document)
    Dim index As Integer
    Dim pagenum As Integer
    Dim newItem As WordsPerPage
    Dim tmpList As New List(Of WordsPerPage)

    Try
        For Each wrd As Range In doc.Words
            pagenum = wrd.Information(WdInformation.wdActiveEndPageNumber)
            Debug.Print("Word {0} is on page {1}", wrd.Text, pagenum)
            index = tmpList.FindIndex(Function(value As WordsPerPage)
                                          Return value.pagenum = pagenum
                                      End Function)
            If index <> -1 Then
                tmpList(index) = New WordsPerPage With {.pagenum = pagenum, .count = tmpList(index).count + 1}
            Else
                ' Unique (or first)
                newItem.count = 1
                newItem.pagenum = pagenum
                tmpList.Add(newItem)
            End If

        Next

    Catch ex As Exception
        WorkerErrorLog.AddLog(ex, Err.Number & " " & Err.Description)
    Finally
        Dim totalWordCount As Long = 0
        For Each item In tmpList
            totalWordCount = totalWordCount + item.count
            Debug.Print("Page {0} has {1} words", item.pagenum, item.count)
        Next
        Debug.Print("Total word count is {0}", totalWordCount)
    End Try
End Sub
结构字页面
作为字符串的公共pagenum
公众认为只要
端部结构
公共子countwordspage(文档作为文档)
将索引设置为整数
Dim pagenum作为整数
将newItem暗显为WordsPerPage
Dim tmpList作为新列表(单词页面)
尝试
对于文档文字中的每个wrd As范围
pagenum=wrd.Information(WdInformation.wdActiveEndPageNumber)
Print(“单词{0}在{1}页上”,wrd.Text,pagenum)
index=tmpList.FindIndex(函数(值为WordsPerPage)
返回值.pagenum=pagenum
终端功能)
如果索引为-1,则
tmpList(index)=带有{.pagenum=pagenum.count=tmpList(index.count+1}的新单词页面
其他的
'唯一(或第一个)
newItem.count=1
newItem.pagenum=pagenum
tmpList.Add(新项目)
如果结束
下一个
特例
WorkerErrorLog.AddLog(例如,错误编号和错误说明)
最后
Dim totalWordCount的长度=0
对于tmpList中的每个项目
totalWordCount=totalWordCount+item.count
Print(“第{0}页有{1}个字”,item.pagenum,item.count)
下一个
Print(“总字数为{0}”,totalWordCount)
结束尝试
端接头

我需要一台windows服务器:使用COM对象;; 请检查此链接

我真的需要这个解决方案。我花了两天的时间来寻找这个东西,我真的很累。如果有人帮我,我会非常感激。你的解决方案有什么问题?你会犯什么错误?请给我们一些上下文。主要问题是我无法找到分页符,以便我可以计算每页中的单词,我有的是换行符我尝试了规范文件97-2003,但没有按照该文件工作。phpword当它将其转换为文本时,它会松开分页符解析文档,并在找到分页符时将其拆分。然后,数一数单独的页面。听起来很复杂,但我认为这是解决您的具体问题的最佳方案。
Structure WordsPerPage
    Public pagenum As String
    Public count As Long
End Structure

Public Sub CountWordsPerPage(doc As Document)
    Dim index As Integer
    Dim pagenum As Integer
    Dim newItem As WordsPerPage
    Dim tmpList As New List(Of WordsPerPage)

    Try
        For Each wrd As Range In doc.Words
            pagenum = wrd.Information(WdInformation.wdActiveEndPageNumber)
            Debug.Print("Word {0} is on page {1}", wrd.Text, pagenum)
            index = tmpList.FindIndex(Function(value As WordsPerPage)
                                          Return value.pagenum = pagenum
                                      End Function)
            If index <> -1 Then
                tmpList(index) = New WordsPerPage With {.pagenum = pagenum, .count = tmpList(index).count + 1}
            Else
                ' Unique (or first)
                newItem.count = 1
                newItem.pagenum = pagenum
                tmpList.Add(newItem)
            End If

        Next

    Catch ex As Exception
        WorkerErrorLog.AddLog(ex, Err.Number & " " & Err.Description)
    Finally
        Dim totalWordCount As Long = 0
        For Each item In tmpList
            totalWordCount = totalWordCount + item.count
            Debug.Print("Page {0} has {1} words", item.pagenum, item.count)
        Next
        Debug.Print("Total word count is {0}", totalWordCount)
    End Try
End Sub