2
我尽量做到:产生的Joomla MS Word文档
- 管理员创建MS Word文档的占位符将被
- 联系uploades MS Word文件,装满数据从的Joomla数据库Joomla和连接它使用SQL语句
- 用户执行“生成MS Word”功能,并从数据库获取充满数据的MS Word文档。
Joomla是否有任何组件可以做到这一点? 我在使用Interop库的应用程序中完成了此操作。
我尽量做到:产生的Joomla MS Word文档
Joomla是否有任何组件可以做到这一点? 我在使用Interop库的应用程序中完成了此操作。
最近,我已经为使用phpdocx和pclzip库的joomla组件做了这个,其中 a * .docx文件是从模板文件生成的。
配置:
$params = Object with form data; // data from requeest
$template = 'xml_file_name'; // jfrom xml file name and *.docx template file name
$pl = '#'; // place holder prefix & suffix: (example: #PLACEHOLDER#)
$date_placehold = '#DATE#'; // will be replaced with current date
$date_formt = 'F j, Y'; // php date format
$template_path = JPATH_COMPONENT_SITE .DS.'templates'.DS.$template.'.docx';
$temp_dir = JPATH_ROOT.DS.'tmp'.DS.'phpdocx-temp-dir'; // + write access
$output_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
$filename = $params->first_name .' - '. $params->second_name.'.docx';
// get names of all form fields of type 'list' from xml file
$lists = (array) ComponentHelper::getJFormLists($template);
// get all field names from the xml file
$fields = (array) ComponentHelper::getJFormFieldsNames($template);
初始化变量:
$doc =& JFactory::getDocument();
$doc->setMimeEncoding($output_mime);
// require phpdocx class
require_once(JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers'.DS.'pclzip.lib.php');
require_once(JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers'.DS.'phpdocx.php');
$phpdocx = new phpdocx($template_path, $temp_dir);
绑定表单字段与用户PARAMS:
foreach($params as $field => $value)
{
if(array_key_exists($field,$lists) && is_array($lists[$field]) && array_key_exists($value, $lists[$field]))
{
// if the field is JFormInput with type "list" its value is not important but its label
$var = $lists[$field][$value];
} else {
$var = $value;
}
// use openxml carriage return on new lines
if(strpos($var, "\n")) {
$var = str_replace("\n", '<w:br/>', $var);
}
$fields[$field] = $var;
}
的foreach应用表单字段:
foreach($fields as $field => $value)
{
// replace placeholder with form value
$phpdocx->assign($pl.strtoupper($field).$pl, $value);
}
// assign date for filled-in applications
if(!empty($date_placehold)
{
$phpdocx->assign($date_placehold, date($date_formt));
}
输出的文件:
$phpdocx->stream($filename, $output_mime);
return true;
随意修改,任何建议表示欢迎。我将代码放在组件的模型中 – WooDzu