1

次のエラーが表示されます。

Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file.' in /home/dyken/public_html/PHPWord/Template.php:109 Stack trace: #0 /home/dyken/public_html/lettersWord.php(40): PHPWord_Template->save('MemberLetters.d...') #1 {main} thrown in /home/dyken/public_html/PHPWord/Template.php on line 109

私はこのコードを持っています:

$sql = "SELECT distinct p.person_id, fname_mi, lname, company_name,
addr1, addr2, city, st, zip, greeting, email, fullName
FROM person p
INNER JOIN person_category c
on c.person_id = p.person_id
WHERE category_id = 1
order by lname, fname_mi, company_name";

$result = mysqli_query($dlink,$sql);

require_once 'PHPWord.php';

while ($row = mysqli_fetch_array($result)) {

$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('letters/testLetter.docx');

$document->setValue('Value1', $row[1]);
$document->setValue('Value2', $row[2]);
$document->setValue('Value3', $row[3]);
$document->setValue('Value4', $row[4]);
$document->setValue('Value5', $row[5]);
$document->setValue('Value6', $row[6]);
$document->setValue('Value7', $row[7]);
$document->setValue('Value8', $row[8]);
$document->setValue('Value9', $row[9]);
$document->setValue('Value10', $row[10]);
$document->setValue('Value11', $row[11]);
$file = 'MemberLetters.docx' . $row[0];
$document->save($file);

if(!$file) {
    // File doesn't exist, output error
    die('file not found');
}
else {
     header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=$file");
    header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
    header("Content-Transfer-Encoding: binary");

    readfile($file);
 }

 unlink($file);

 exit;
  }

testLetter.docxこれが含まれています:

${Value1} ${Value2}
${Value3}
${Value4}
${Value5}
${Value6}, ${Value7}  ${Value8}

レターに値を入力するためのクエリを取得できません。

クエリは Web サイトの別の場所に結果を生成するので、それが機能することはわかっています。

$dlink$host, $user, $password$dbnameつながり

レター フォルダーにドキュメントを取得していますが、期待したほど多くはなく、クエリからのデータではなく、 などを含むtestLetter.docxすべての正確なコピーです。${Value1}

コードのさまざまなバリエーションを試しましたが、$Values. 誰かがこれで私を助けてくれますか? 私はPHPWordが初めてです。

4

1 に答える 1

0

私もしばらくこれに苦労してきましたが、同じ種類の問題のようです。Word はドキュメントの作成方法に応じて異なる種類の xml を生成するようです。始まり。

インターネットで検索すると、https://phpword.codeplex.com/workitem/49でこのコードが見つかりました。setValue メソッドの動作を置き換えることです。

また、私が話していることの詳細については、http://phpword.codeplex.com/discussions/268012を参照してください。

于 2014-07-01T15:18:34.643 に答える