先要了解grid++report
控制器代码
// 设置报表数据这里可以自己开发
$orderArray ['EmployeeID'] = '01';
$orderArray ['Title'] = '经理';
$orderArray ['name'] = '张三';
// 报表中要得到的数据格式
$xmlReportData = get_reports_xml_byarray ( $orderArray );
$this->assign ( 'xmlReportData', $xmlReportData );
// 要打印的报表文件
$reportName = '1f.grf';
$this->assign ( 'reportName', $reportName );
$this->display();
function方法/**
* 将数组转化为可用的报表格式
*
* @param unknown $array
* @return string
*/
function get_reports_xml_byarray($array) {
$XMLText = "<report>";
// 得到报表明细字段
$XMLText .= "<rows>";
foreach ( $array ['rows'] as $key => $value ) {
$XMLText .= "<row>";
foreach ( $value as $keySub => $valueSub ) {
$XMLText .= "<" . $keySub . ">" . $valueSub . "</" . $keySub . ">";
}
$XMLText .= "</row>";
}
$XMLText .= "</rows>";
// 得到报表的其它参数
$XMLText .= "<_grparam>";
foreach ( $array as $key => $value ) {
if (! is_array ( $value )) {
$XMLText .= "<" . $key . ">" . $value . "</" . $key . ">";
}
}
$XMLText .= "</_grparam>";
$XMLText .= "</report>";
return $XMLText;
}
前台代码<html>
<head>
<title></title>
<script src="__public__/grid/CreateControl.js" type="text/javascript"></script>
</head>
<body>
<div>
<button type="button" onclick="printView();" class="button button-danger">打印报表</button>
</div>
<a href="http://weixin.gsjfjt.com/demo_qyh/grinstall/grbsctl6.exe">下载插件</a>
<script type="text/javascript">
//打印报表函数 建立报表对象
CreateReport("Report");
function printView() {
//读取报表模版
Report.LoadFromURL("__public__/grf/{$reportName}");
//加载报表数据
Report.LoadDataFromXML("{$xmlReportData}");
//打印预览
Report.PrintPreview(true);
};
</script>
</body>
</html>
咨询QQ:409077741http://weixin.gsjfjt.com/demo_qyh/index.php/Home/Grid