4

実際、私はms wordファイルからページを数えようとしています.このphpスクリプトを使用していますが、正確な結果が表示されず、スクリプトはそれほど高速ではありません. より良いスクリプトを入手するのを手伝ってくれる人はいますか。

$word = new COM("word.application");
if (!$word) {
  echo ("Could not initialise MS Word object.\n"); 
  exit(1);
}
$word->Documents->Open(realpath("d:\\Test\\t.docx")); 

$pages = $word->ActiveDocument->BuiltInDocumentProperties(14); 
echo "Number of pages: " . $pages->value;

$word->ActiveDocument->Close(false); 
$word->Quit(); 
$word = null; 
unset($word);
4

1 に答える 1

2

これを試して

$filename = "PATH";
$word = new COM("Word.Application");
$word->visible = true;
$word->Documents->Open($filename);

$wdStatisticPages = 2; // Value that corresponds to the Page count in the Statistics
$word->ActiveDocument->ComputeStatistics($wdStatisticPages);

echo "Total Page(s) : ". $word->ActiveDocument->ComputeStatistics($wdStatisticPages);  
$word->ActiveDocument->PrintOut();
$word->ActiveDocument->Close();
$word->Quit();

基本的にはComputeStatistics()、正しい値をパラメータとしてメソッドを呼び出します。

于 2013-04-26T07:03:34.343 に答える