php - 使用 php 以读取模式打开 Word 文档?

标签 php

我想使用 PHP 在浏览器中阅读 Word 文档。 我已经尝试了两个多小时,但无法正常工作。 有人可以帮我做这个吗?

最佳答案

由于您在关于具体要求或服务器设置的问题中不太详细,这将帮助您入门并回答问题。

<?php
$DocumentPath="C:/xampp/htdocs/test.doc";
//Create an instance of the Word application
$word = new COM("word.application") or die("Unable to instantiate application object");
//Creating an instance of the Word Document object
$wordDocument = new COM("word.document") or die("Unable to instantiate document object");
$word->Visible = 0;
//Open up an empty document
$wordDocument = $word->Documents->Open($DocumentPath);

//Create the filename for the HTML version
$HTMLPath = substr_replace($DocumentPath, 'html', -3, 3);
//Save the document as HTML
$wordDocument->SaveAs($HTMLPath, 3);
// clean up
$wordDocument = null;
$word->Quit();
$word = null;
// read the newly-created document
readfile($HTMLPath);
//delete the file
unlink($HTMLPath)
?>

关于php - 使用 php 以读取模式打开 Word 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144023/

相关文章:

PHP 在 Bluehost 上使用 PEAR Mail 时包含路径问题

php - Apache 重写规则和 POST 数据

php - 按间隔分组显示为零

javascript - 在 JavaScript 中将 PHP 数组转换为 JSON 数组时, ","成为数组的第一个元素

php - 在每个循环 Laravel 中求和

php - 对于每个循环不起作用

php - 如何在 Yii 中创建多语言标签

php - 实例化从 AwsClient 子类扩展的类时出错

php - 如何制作乘/除sql表?

javascript - 等待 ajax 函数完成,直到使用间隔再次重新加载该函数