Page 1 of 1

Customizing Export (v2021)

Posted: Fri Feb 26, 2021 10:58 am
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).


Re: Customizing Export (v2021)

Posted: Fri Dec 02, 2022 6:15 pm
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 ?


Re: Customizing Export (v2021)

Posted: Sat Dec 03, 2022 9:15 am
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.


Re: Customizing Export (v2021)

Posted: Wed Jan 31, 2024 7:23 am
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


Re: Customizing Export (v2021)

Posted: Wed Jan 31, 2024 10:54 am
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.


Re: Customizing Export (v2021)

Posted: Fri Feb 09, 2024 10:23 pm
by philmills

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

viewtopic.php?t=54937