There are two ways:
Customize Export Class
Exporting a table is done by the ExportXXX
classes (e.g. dompdf extension uses ExportPdf
, PhpSpreadsheet extension uses ExportExcel5
and ExportExcel2007
).
You may customize export by overriding methods in the class. For example, if you want to add something before the first row, you may customize the ExportExcel5
class and implement the exportTableHeader()
method, e.g. (Note: This is to explain the idea only, not code for copy and paste, you must modify it yourself as needed.)
// Extend the original class
class MyExportExcel5 extends ExportExcel5 {
// Table header
public function exportTableHeader() { // override
$this->RowCnt++; // Increase the row count
$this->setCellValueByColumnAndRow(1, $this->RowCnt, "My Title"); // Set value at the first cell of first row
}
}
// Replace the default ExportExcel class
Config("EXPORT_CLASSES.excel", "MyExportExcel5'); // Note: For tables only. This example is not applicable to reports.
You can put your code under server side Global Code.
Similarly for other ExportXXX
classes.
OR
Use Server Events (Page_Exporting, Row_Export and Page_Exported)
You may also try Page_Exporting server event, from Server Events and Client Scripts in the help file:
This event will be called before the page is exported. You can use this event to add your additional code to the beginning of file to be exported. Return false to skip default export and use Row_Export event. Return true to use default export and skip Row_Export event. Check $this->Export
for the export type (e.g. "excel", "word"). The content of the export document is $this->ExportDoc->Text
(except PhpSpreadsheet/PHPWord).