PHP完全自学手册(珍藏版) 中文pdf扫描版下载
$phpWord = new \PhpOffice\PhpWord\PhpWord(); // Every element you want to append to the word document is placed in a section. // To create a basic section: $section = $phpWord->addSection(); // After creating a section, you can append elements: $section->addText('Hello world!'); // You can directly style your text by giving the addText function an array: $section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); // If you often need the same style again you can create a user defined style // to the word document and give the addText function the name of the style: $phpWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also put the appended element to local object like this: $fontStyle = new \PhpOffice\PhpWord\Style\Font(); $fontStyle->setBold(true); $fontStyle->setName('Verdana'); $fontStyle->setSize(22); $myTextElement = $section->addText('Hello World!'); $myTextElement->setFontStyle($fontStyle); // Finally, write the document: $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('helloWorld.docx'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText'); $objWriter->save('helloWorld.odt'); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF'); $objWriter->save('helloWorld.rtf'); 下载地址: https://github.com/PHPOffice/PHPWord
转载请注明:谷谷点程序 » php读word内容的源码下载