项目中要用到通过phpexcel和word导入数据,这次使用了phpOffice,excel识别的很准确,导入的word中还能保留图片(会转成base64)非常好用。

首先使用composer安装

composer require phpoffice/phpspreadsheet
  • 1.

导入excel

$file = root_path()."public\\excel\\plan.xlsx";
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
echo($xmlWriter->getContent());//结果
  • 1.
  • 2.
  • 3.
  • 4.

导入word

$file = root_path()."public\\word\\demo.docx";
$phpWord = \PhpOffice\PhpWord\IOFactory::load($file);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
echo($xmlWriter->getContent());//结果
  • 1.
  • 2.
  • 3.
  • 4.

是不是很方便,用起来吧