如何为每个代码块使用 PHPWord
How to PHPWord foreach codeBlock
我需要将MYSQL数据库中的数据转换成Word。
Word 文件
我的代码
require './modules/vendor/autoload.php';
require 'core.php';
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(__DIR__ . '/wordfile.docx');
$topshiriqnoma = $connection->table('topshiriqnoma')->where('chiqinn', $id)->orderBy('id', 'desc')->paginate(50);
$nomi = $connection->table('topshiriqnoma')->where('chiqinn', $id)->orderBy('id', 'desc')->first();
unlink(UPLOAD_PATH . '/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
foreach ($topshiriqnoma as $item) {
$summahamma = str_replace(" ", "", $item->sum); // 70
if (strpos($summahamma, ',') == true) {
$mas = explode(',', $summahamma);
$summasoz = convertNumberToWord($mas['0']) . " сўм " . $mas['1'] . " тийин";
$summaraqam = number_format((float)$summahamma, 2, '.', ' ');
} elseif (strpos($summahamma, '.') == true) {
$mas = explode('.', $summahamma);
$summasoz = convertNumberToWord($mas['0']) . " сўм " . $mas['1'] . " тийин";
$summaraqam = number_format((float)$summahamma, 2, '.', ' ');
} else {
$summasoz = convertNumberToWord($item->sum) . " сўм";
$summaraqam = number_format((float)$summahamma, 2, ',', ' ');
}
$replacements[] = [
'no' => $item->no,
'sana' => $item->sana,
'tashkilot' => $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm),
'chiqxr' => $item->chiqxr,
'chiqinn' => $item->chiqinn,
'chiqbk' => $item->chiqbk,
'chiqmfo' => $item->chimfo,
'summa' => $summaraqam,
'kirtash' => $item->kirnm." ".shaklqisqa($item->kirsh, $item->kirnm),
'kirxr' => $item->kirxr,
'kirinn' => $r = (0 != $item->kirinn) ? $item->kirinn : '',
'kirbk' => $item->kirbk,
'kirmfo' => $item->kirmfo,
'summasoz' => $summasoz,
'maqsad' => $item->maqsad,
'boshliq' => $item->bosh,
'xisobchi' => $item->bux
];
}
$templateProcessor->cloneRow('nameblock', count($replacements));
$templateProcessor->saveAs(UPLOAD_PATH . '/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
header('Location: ' . $home . '/upload/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
但是如果Word文件是这样的话,一切正常。问题是它必须在 Table 模式(第一张图片)模式下工作。
它没有用,因为我使用了一个更旧的 PHPWord。我安装了一个新的 PHPword,一切正常
我需要将MYSQL数据库中的数据转换成Word。
Word 文件
我的代码
require './modules/vendor/autoload.php';
require 'core.php';
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(__DIR__ . '/wordfile.docx');
$topshiriqnoma = $connection->table('topshiriqnoma')->where('chiqinn', $id)->orderBy('id', 'desc')->paginate(50);
$nomi = $connection->table('topshiriqnoma')->where('chiqinn', $id)->orderBy('id', 'desc')->first();
unlink(UPLOAD_PATH . '/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
foreach ($topshiriqnoma as $item) {
$summahamma = str_replace(" ", "", $item->sum); // 70
if (strpos($summahamma, ',') == true) {
$mas = explode(',', $summahamma);
$summasoz = convertNumberToWord($mas['0']) . " сўм " . $mas['1'] . " тийин";
$summaraqam = number_format((float)$summahamma, 2, '.', ' ');
} elseif (strpos($summahamma, '.') == true) {
$mas = explode('.', $summahamma);
$summasoz = convertNumberToWord($mas['0']) . " сўм " . $mas['1'] . " тийин";
$summaraqam = number_format((float)$summahamma, 2, '.', ' ');
} else {
$summasoz = convertNumberToWord($item->sum) . " сўм";
$summaraqam = number_format((float)$summahamma, 2, ',', ' ');
}
$replacements[] = [
'no' => $item->no,
'sana' => $item->sana,
'tashkilot' => $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm),
'chiqxr' => $item->chiqxr,
'chiqinn' => $item->chiqinn,
'chiqbk' => $item->chiqbk,
'chiqmfo' => $item->chimfo,
'summa' => $summaraqam,
'kirtash' => $item->kirnm." ".shaklqisqa($item->kirsh, $item->kirnm),
'kirxr' => $item->kirxr,
'kirinn' => $r = (0 != $item->kirinn) ? $item->kirinn : '',
'kirbk' => $item->kirbk,
'kirmfo' => $item->kirmfo,
'summasoz' => $summasoz,
'maqsad' => $item->maqsad,
'boshliq' => $item->bosh,
'xisobchi' => $item->bux
];
}
$templateProcessor->cloneRow('nameblock', count($replacements));
$templateProcessor->saveAs(UPLOAD_PATH . '/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
header('Location: ' . $home . '/upload/porucheniya/' . $item->chiqnm." ".shaklqisqa($item->chiqsh, $item->chiqnm) . '.docx');
但是如果Word文件是这样的话,一切正常。问题是它必须在 Table 模式(第一张图片)模式下工作。
它没有用,因为我使用了一个更旧的 PHPWord。我安装了一个新的 PHPword,一切正常