使用COM打开Word
我实际上正在尝试从 http://php.net/manual/en 找到的一些代码/class.com.php
<?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;
?>
但这似乎不起作用。我使用的是 Word 2007,我得到以下信息:
已加载 Word,版本 12.0 致命错误:第 14 行 C:\xampp\htdocs\final\testq.php 中调用未定义的方法变体::SaveAs()
任何人都可以解决这个问题吗?是因为我用的是Word 2007吗?
I am actually trying some codes i found from http://php.net/manual/en/class.com.php
<?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;
?>
But this does not seem to work. I am using Word 2007 and i get the following:
Loaded Word, version 12.0
Fatal error: Call to undefined method variant::SaveAs() in C:\xampp\htdocs\final\testq.php on line 14
Can anyone solve this problem? Is it because i am using Word 2007?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Documents
对象是一个 Collection 对象,而不是一个数组。尝试:或者
The
Documents
object is a Collection object, not an array. Try:Or
您的示例对我来说运行良好,在 Window 7 上使用 Word 2003 和 Word 2007。因此,我认为问题可能是 Word 安装/配置不正确。要进行故障排除,请执行以下操作:
%APPDATA%\Microsoft\Templates\
并重命名 Normal.dot(x) 文件Your sample runs fine for me, both with Word 2003 and Word 2007 on Window 7. Therefore I assume that the problem might be an incorrectly installed/configured Word. For troubleshooting do the following:
%APPDATA%\Microsoft\Templates\
and rename the Normal.dot(x) file我通过使用解决了这个问题: http://www.phpbuilder.net/columns/venkatesan20030501.php3< /a>?
感谢您的回复
I solved it by using : http://www.phpbuilder.net/columns/venkatesan20030501.php3?
Thanks for your replies