Customizing Export (v2021)

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

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

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


philmills
User
Posts: 535

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::

// 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?

// 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: 9284

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.


danilo.macri
User
Posts: 92

Post by danilo.macri »

I tried but it doesn't work... I have a text field formatted in html... I would like it to export only that field, without a table... just the text formatted in html


arbei
User
Posts: 9284

Post by arbei »

Then you need to override the exportField() method to check the field name and only export that field. You may post your code for discussion.


philmills
User
Posts: 535

Post by philmills »

You may also find this thread useful, as it deals with PDF page break issues:

viewtopic.php?t=54937


Post Reply