在MS中将MS Word文档转换为html

时间:2011-01-13 13:06:19

标签: php html ms-word

如何在PHP中将Microsoft Word文档转换为html?我正在使用Windows,并听说COM包就可以了。

2 个答案:

答案 0 :(得分:4)

请参阅COM extension of PHP

the PHP site的使用示例:

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

答案 1 :(得分:0)

尝试使用Print2Flash获取显示原始Word文档的可用HTML页面。使用此解决方案不会丢失和保留格式,字体和图像。有人可能会得到一个可用的PHP样本,演示如何从可供下载的p2f SDK中完成:http://print2flash.com/download.php除了SDK之外,还需要从同一页面下载并安装Print2Flash。 PHP代码非常简单,最小代码似乎是这样的:

$p2f = new COM("Print2Flash4.Server2")
$p2f->ConvertFile($sourcefile,$fsname);

您可以在此处设置许多其他选项。请参阅sdk的完整示例代码以了解这些选项。