목적은 Microsoft Word 파일의 정확한 단어 수를 얻는 것입니다. Apache와 PHP를 실행하는 Windows 서버가 있습니다. 기본적으로 문서의 모든 내용을 가져와 preg_match_all("/\S+/", $string, $matches); return count($matches[0]);
을 통해 내용을 실행하는 웹 서비스가 해당 컴퓨터에서 실행됩니다. 잘 작동하지만 정확하지 않습니다. 내가 Word에서이 매크로를 실행하면Word 매크로에서 PHP로 돌아 가기
Sub GetWordCountBreakdown()
Dim x As Integer
Dim TotalWords As Long
Dim FieldWords As Long
TotalWords = ActiveDocument.ComputeStatistics(wdStatisticWords)
For x = 1 To ActiveDocument.Fields.Count
If ActiveDocument.Fields.Item(x).Result.ComputeStatistics(wdStatisticWords) > 25 Then
FieldWords = FieldWords + ActiveDocument.Fields.Item(x).Result.ComputeStatistics(wdStatisticWords)
End If
Next x
MsgBox (TotalWords & " - " & FieldWords & " = " & TotalWords - FieldWords)
End Sub`
,이 문서에있는 모든 단어와 참조를 카운트 나에게 깔끔한 작은 경고 상자를 제공합니다 : 그래서 우리는 다음과 같은 매크로를 썼다. 나는 PHP로 그 값을 반환하는 방법을 잘 모르겠다. 그래서 나의 webservice는 그것들을 다시 나에게 전달할 수있다.
업데이트 : 나는이 매크로를 PHP로 다시 작성하고 올바른 단어 수를 얻을 수있었습니다. 기본적으로 :
$word = new COM("Word.Application")
$word->Documents->Open(file);
$wdStatisticWords = 0;
$wordcount = $word->ActiveDocument->ComputeStatistics($wdStatisticWords);
등
또한 현재 시스템이 정확하지 않은 이유는 무엇입니까? – JakeSteam
필자는 주요 문서의 텍스트 만 원하고 머리글이나 각주는 필요하지 않습니다. 만약 내가'$ content = $ word-> ActiveDocument-> Content;를하면 문서의 내용을 얻기 위해 모든 문자열이 하나의 긴 문자열로 주어 지므로 올바르지 않습니다. – Vic