<?php
$word 
= new COM("word.application") or die("无法启动 Word 程序!"
);

$word->Visible 1
;
$doc $word->Documents->Add
();

$doc->Sections->Add($word->Selection->Range,0);
// 增加一个分节
$Section $doc->Sections(1); 
// 获取第一小节对象
$Range   $Section->Range;   
// 产生 Range 对象
$Table   $doc->Tables->Add($Range ,510); 
// 产生 5x10的表格

// 将数据塞入表格
for ($i=1$i<=10$i
++) {
    for (
$j=1$j<=5$j
++) {
        
$Cell      $Table->Cell($j$i
);
        
$CellRange $Cell->Range
;
        
$CellRange->InsertBefore(chr(0x40+$j).chr(0x40+$i
));
    }
}

$word->Documents[1]->SaveAs("c:\\word.doc"
);
$word->Quit
();
$word->Release
();
$word null
;
?>