如何使用php word将ckediter文本转换为word

时间:2019-05-27 07:51:22

标签: laravel phpword

我正在使用ckeditor创建一个博客,并使用wordformatePHPWORD中下载该博客。 但是当我打开下载word doc时,它没有打开,并给出了XML解析错误

我正在LARAVEL上尝试

public function createWordDocuments( Request $request ,$id)
{

    $data= Templete::where('id',$id)->first();
    $wordTest= new \PhpOffice\PhpWord\PhpWord();
    $newSection= $wordTest->addSection();
    $wordText =json_decode($data['word']) ;
    //echo $wordText;exit;
    $newSection->addText($wordText);


   \PhpOffice\PhpWord\Shared\Html::addHtml($newSection, $wordText , false, false);

    $objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest,'Word2007');
    try
    {
        ob_start();
        $objectWriter->save(storage_path('TestWordFile.docx'));
        ob_get_clean();
    }
    catch(Exception $e) {
    }
    return response()->download(storage_path('TestWordFile.docx'));

    session()->flash('message','file download ');
    return redirect()->to('/text');

}

我要在我下载的word文件中的ckediter工具中添加文本样式。

0 个答案:

没有答案