phpoffice文档笔记
阅读原文时间:2023年07月10日阅读:2

目录

phpword

<?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, "<p style='color:#FF4400'>test</p><p><img src='http://t.com/image.png'/></p>", 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');
    }
}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章