Hello guys, Im producing reports in excel and pdf using php excel and mpdf But when I create a report, In my excel report and pdf, it also includes the word Displaying records 10-10 which is present in my CGridView and also there are some numbers which I really dont where it came from.
Here is my code in producing excel and pdf in my controller:
else if (isset($_POST['PDF'])) {
$account->attributes = $_POST['AccountForm'];
$account->searchData2();
$connection = Yii::app()->db;
$sql = $account->sql2;
$rowcountsql = $account->rowcount2;
$key = "AuditTrailID";
$command = $connection->createCommand($rowcountsql);
$count = $command->queryScalar(); // provide count for pagination
// create data provider that works with CGridView
$dataProvider = new CSqlDataProvider($sql, array(
'keyField' => $key,
'totalItemCount' => $count,
'pagination' => array(
'pageSize' => $count,
),
));
$mPDF1 = Yii::app()->ePdf->mpdf();
# You can easily override default constructor's params
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
# render (full page)
//$mPDF1->WriteHTML($this->render('index', array(), true));
# Load a stylesheet
$stylesheet = file_get_contents(Yii::getPathOfAlias('webroot.css') . '/main.css');
$mPDF1->WriteHTML($stylesheet, 1);
# renderPartial (only 'view' of current controller)
$mPDF1->WriteHTML($this->renderPartial('export2', array('dataProvider' => $dataProvider, 'account' => $account, '$auditdate' => $account->auditdate), true));
# Outputs ready PDF
$mPDF1->Output();
}
Excel:
$else if (isset($_POST['Excel'])) {
$account->attributes = $_POST['AccountForm'];
$connection = Yii::app()->db;
$account->searchData2();
$sql = $account->sql2;
$rowcountsql = $account->rowcount2;
$key = "AuditTrailID";
$command = $connection->createCommand($rowcountsql);
$count = $command->queryScalar(); // provide count for pagination
// create data provider that works with CGridView
$dataProvider = new CSqlDataProvider($sql, array(
'keyField' => $key,
'totalItemCount' => $count,
'pagination' => array(
'pageSize' => $count,
),
));
Yii::app()->request->sendFile("AuditTrail Report.xls", $this->renderPartial('export2', array('dataProvider' => $dataProvider, 'account' => $account, '$auditdate' => $account->auditdate),TRUE));
$this->render('audittrail', array('dataProvider' => $dataProvider, 'account' => $account));
}