programic / html2docx
将 html 转换为 docx
v1.6
2020-11-17 10:23 UTC
Requires
- phpoffice/phpword: ^0.17.0
README
使用本包可以将 HTML 转换为 Word、ODText、RTF 和 PDF。
使用方法
为了使用此包,您需要通过 composer 安装它。
在您的 composer.json
{ "require": { "programic/html2docx": "^1.0" } }
在您的代码中
<?php use Programic\Html2Docx\Docx; $docx = new Docx($settings); $docx->setContent($content); $docx->save($location, $writerInterface='Word2007');
设置
'base_root' => url('/'), // Required for link elements - change it to your domain.
'base_path' => base_path(), // Path from base_root to whatever url your links are relative to.
'current_style' => ['size' => '11'], // The PHPWord style on the top element
'parents' => [0 => 'body'], // Our parent is body.
'list_depth' => 0, // This is the current depth of any current list.
'context' => 'section', // Possible values - section, footer or header.
'pseudo_list' => true, // NOTE: Word lists not yet supported (TRUE is the only option at present).
'pseudo_list_indicator_font_name' => 'Wingdings', // Bullet indicator font.
'pseudo_list_indicator_font_size' => '7', // Bullet indicator size.
'pseudo_list_indicator_character' => 'l ', // Gives a circle bullet point with wingdings.
'table_allowed' => true, // Tables cannot be nested in PHPWord.
'treat_div_as_paragraph' => true, // If set to TRUE, each new div will trigger a new line in the Word document.
// This is an array (the "style sheet")
'style_sheet' => [], // check hasStyles trait for options
Writer 接口
writerInterface 用于指定我们将 HTML 转换为哪种格式。选项包括
- Word2007
- ODText
- RTF