【发布时间】:2023-03-20 01:08:01
【问题描述】:
我正在尝试使用 Yii 生成一个 ms-word 文档。我发现很难做到。我找到了这个例子Generating ms-word,但我无法让它工作。
View:
echo CHtml::ajaxLink(
'Generate Word',
CController::createUrl('Calculator/generateWord'), array(
'type' => 'POST',
), array('id'=>'gen_word')
);
Controller:
$var = "hello";
$div = $this->renderPartial('graphs/print', array('var'=>$var), true);
header("Pragma: no-cache"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=\"test.doc");
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
echo $div;
graphs/print:
<table>
<tr>
<td>This is just s test</td>
</tr>
<tr>
<td><?php echo $var; ?></td>
</tr>
</table>
当我点击“生成单词”链接时,它什么也没做。
【问题讨论】:
-
如果docx文件没有问题,可以尝试使用phpword来操作word docx文件。这里是如何使用:stackoverflow.com/a/23943396/2327332
标签: yii frameworks ms-word