iszjw 发表于 2017-3-25 13:13:52

php操作word画表格

<?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 ,5, 10); // 产生 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->SaveAs("c:\\word.doc");
$word->Quit();
$word->Release();
$word = null;
?>
页: [1]
查看完整版本: php操作word画表格