わかりました、それで私は見つけることができるPHPWordクラスに問題があります:http://phpword.codeplex.com
奇妙なことに、「example」ファイルでこれと同じコードを使用すると、生成に問題なく機能します。ヘッダーを使用してダウンロードを強制しない場合、ファイルは正常に開きます。ただし、ヘッダーでこのコードを使用すると、ダウンロード時にファイルが破損していて開くことができないというエラーがワードファイルにスローされますが、正常に開きます。
public function export()
{
// Load PHPWORD Library
$this->load->library('PHPWord');
$sec = $this->phpword->createSection($secStyle);
$header = $sec->createHeader();
$header->addWatermark('images/CC_watermark.png', array('marginTop'=>1015, 'marginLeft'=>-80));
$resultSelected = $this->input->post('cbox');
foreach($resultSelected as $row)
{
$sec->addText($row);
echo $row."<br>";
}
$fileName = "Plan_Generate_".date('Ymd').".docx";
// Force Download
$filePath = $fileName;
$fileName = basename($filePath);
// $fileSize = filesize($filePath);
// Output headers.
header("Cache-Control: private");
header("Content-Type: application/stream");
// header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
// Output file.
// readfile ($filePath);
// exit();
// Save File
// $fileName = "files/SomethingNew_".date("Ymd").".docx";
$objWriter = PHPWord_IOFactory::createWriter($this->phpword, 'Word2007');
$objWriter->save('php://output');
}
これは、ファイルを生成しようとするときに使用しているコードです。私が抱えている問題は、ダウンロードを強制しようとするとエラーが発生することです。助けてくれてありがとう!質問を完全に理解していない場合は、質問してください。
アップデート:
これが私が受け取っているエラーの画像です。迅速な対応に感謝します。実際にCodeignitersの方法でTommを試してみます。朝。