mkdreams / mdword
OFFICE WORD 动态数据 绑定数据 生成报告;OFFICE WORD Dynamic data binding data generation report.
Installs: 1 160
Dependents: 1
Suggesters: 0
Security: 0
Stars: 50
Watchers: 2
Forks: 9
Open Issues: 0
Requires
- php: >=5.6.0
README
中文文档
Project General Name
Template: a word which will be revised.
Block: the part which will be replaced or cloned.
Project Introduction
Main Use: to generate word dynamically.
Advantage: focus only on dynamic data and logic, rather than adjusting the style, which can modulate the template with the help of office word.
Comparison between MDword & PHPword
- PHP Package.
- Both can be used to generate office word.
- PHPword concentrates on writing elements one by one. However, it is more powerful and efficient for Mdword just to revise them on the template.
- For updating text styles, adding covers, headers and footers, MDword just modifies the template by office word, while PHPword complicate the task-adjusting every element.
- Directories(Table of content) can be automatically generated.
Tutotials
// Method 1
composer require mkdreams/mdword
// Method 2, Autoloading Template
require_once('Autoloader.php');
-
Invocation Methods (more and richer approaches, for example: tests\samples\simple for readme, such as catalog, sequence number, etc.)
// New class,load template
$TemplateProcessor = new WordProcessor();
$template = 'temple.docx';
$TemplateProcessor->load($template);
// Set Value
$TemplateProcessor->setValue('value', 'r-value');
// Clone
$TemplateProcessor->clones('people', 3);
$TemplateProcessor->setValue('name#0', 'colin0');
$TemplateProcessor->setValue('name#1', [
['text'=>'colin1','style'=>'style','type'=>MDWORD_TEXT],
['text'=>1,'type'=>MDWORD_BREAK],
['text'=>'86','style'=>'style','type'=>MDWORD_TEXT]
]);
$TemplateProcessor->setValue('name#2', 'colin2');
$TemplateProcessor->setValue('sex#1', 'woman');
$TemplateProcessor->setValue('age#0', '280');
$TemplateProcessor->setValue('age#1', '281');
$TemplateProcessor->setValue('age#2', '282');
// set value for image
$TemplateProcessor->setImageValue('image', dirname(__FILE__).'/logo.jpg');
// Delete a paragraph
$TemplateProcessor->deleteP('style');
// Save
$rtemplate = __DIR__.'/r-temple.docx';
$TemplateProcessor->saveAs($rtemplate);