multi-store/app/common/service/xlsx/Beforehand.php
mkm c370a96e60 添加订单标签导出功能
- 在 StoreOrderController 中新增 export_tags 方法,用于导出订单标签
- 在 Beforehand 类中调整字体样式大小
2024-10-09 15:01:05 +08:00

47 lines
1.7 KiB
PHP

<?php
namespace app\common\service\xlsx;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Converter;
class Beforehand
{
public function export($data,$system_store)
{
// 创建一个新的PHPWord文档
$phpWord = new PhpWord();
// 添加一个节
$section = $phpWord->addSection(array(
'pageSizeW' => Converter::cmToTwip(4), // 宽度转换为twips
'pageSizeH' => Converter::cmToTwip(2), // 高度转换为twips
'marginLeft' => Converter::cmToTwip(0.2),
'marginRight' => Converter::cmToTwip(0),
'marginTop' => Converter::cmToTwip(0.2),
'marginBottom' => Converter::cmToTwip(0),
));
$fontStyle = ['name' => 'Arial', 'size' => 10, 'bold' => true];
$fontStyle1 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle2 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
$fontStyle3 = ['name' => 'Arial', 'size' => 8, 'bold' => true];
foreach ($data as $k => $v) {
$textRun =$section->addTextRun();
$textRun->addText($v['system_store'], $fontStyle);
$textRun->addText(' '.mb_substr($v['subtitle'], 0, 8, 'UTF-8'), $fontStyle1);
$section->addText(mb_substr( $v['store_name'], 0, 16, 'UTF-8'), $fontStyle2);
$section->addText($v['address'], $fontStyle3);
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$url = '/export/' . date('Y-m') . '/' . $system_store.'标签单-'.date('Y-m-d H:i') . '.docx';
$file_path = public_path() . $url;
// 保存文件到 public 下
$objWriter->save($file_path);
return getenv('APP_URL').$url;
}
}