<?php
function importWord(){
Core_Auth::checkauth("product_manage");
global $db;
$searchsql = " WHERE 1=1";
$sql = "SELECT a.*,c.cname".
" FROM ".DB_PREFIX."product AS a".
" LEFT JOIN ".DB_PREFIX."productcate AS c ON a.cid=c.cid".
$searchsql." ORDER BY a.id LIMIT 0, 4";
$product = $db->getall($sql);
// 创建PHPWord对象
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// 将HTML内容导入到Word
$section = $phpWord->addSection();
$width = 2000;
$fontStyle = array('bold' => true, 'align' => 'center');
$section->addTitle('配置清单详情', 1);
$table = $section->addTable();
$table->addRow(900);
foreach ($product as $row) {
if ($row['uploadfiles']) {
$img = explode('#', $row['uploadfiles'])[0];
$img = 'https:' . $img;
$table->addCell($width)->addTextRun()->addImage(
$img,
array(
'width' => 100,
'height' => 100,
'align' => 'center'
)
);
}
}
$table->addRow(900);
foreach ($product as $row) {
$table->addCell($width)->addText($row['title'],$fontStyle);
}
//添加行
$table->addRow(900);
//添加单元格
foreach ($product as $row) {
$table->addCell($width)->addText($row['hits'],$fontStyle);
}
// 保存Word文档
$filename = 'export.docx';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");
}
?>上一篇:php新闻内容过滤
下一篇:添加权限(10.1)