phpoffice文档笔记
目录
- phpword
- html转word
- phpexcel
- 从数据库导出
phpword
html转word
<?php
namespace app\index\controller;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\Html;
class Index extends Controller
{
public function index(){
$word = new PhpWord();
$content = $word->addSection();
$html = new Html();
$html::addHtml($content, "test

", false, false);
$word->save('test.docx');
}
}
图片路径要么网络地址,要么图片在服务器的绝对路径
phpexcel
从数据库导出
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Index {
public function export()
{
$model = new Spreadsheet();
$sheet = $model->getActiveSheet();
$model->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
//设置值,单元格,值
$sheet->setCellValue('A1', 'ID');
$sheet->setCellValue('A2', '1');
//实例化类
$writer = new Xlsx($model);
//保存到本地
$writer->save(test.xlsx');
}
}