Customizing Export (v2021)

Tips submitted by PHPMaker users
Post Reply
arbei
User
Posts: 7915

Customizing Export (v2021)

Post by arbei »

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.)

Code: Select all

// 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');

You can put your code under server side Global Code (see Server Events and Client Scripts in the help file).

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).


philmills
User
Posts: 439

Post by philmills »

I'm customizing export class for pdf, and I'm trying to apply it to Master/Detail export, but i don't fully understand how this is supposed to work.

This code goes in Global Code::

Code: Select all

// Extend the original pdf export class
class MyExportPdf extends ExportPdf {
	// 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
	}
}

I'm guessing this code goes in Page_Load but for which table?

Code: Select all

// Replace the default ExportPDF class 
Config("EXPORT_CLASSES.pdf",  'MyExportPdf');

Do I have to create a fresh class for each detail table, or can I somehow use the same class ?


arbei
User
Posts: 7915

Post by arbei »

The example was for PhpSpreadsheet, you cannot use the same code for dompdf. You may refer to the source of the original ExportPdf class and then customize.


Post Reply