This following customization will show you how you can change the separator character for Export to CSV file in web applications that generated by PHPMaker. As we have already known, the default separator character that used by PHPMaker is a comma (,) character. In this following example, let's say we will change it become the semicolon character.
We will customize the PHPMaker template to achieve this, so that you can use the template for your future project. By following this customization, then you will see how PHPMaker has provided us the great Class for Export to ... feature. You will also learn how you can extend the base class which is being used for Export feature according to your needs. This is one of the features provided by PHPMaker that I love it so much.
[hidepost]
-
Open your \Script\phpfn.php file, and find this code:
class cExportCsv extends cExportBase { var $QuoteChar = "\""; // Style function ChangeStyle($style) { $this->Horizontal = TRUE; } // Table header function ExportTableHeader() { // Skip } // Export a value (caption, field value, or aggregate) function ExportValueEx(&$fld, $val, $usestyle = TRUE) { if ($this->Line <> "") $this->Line .= ","; $this->Line .= $this->QuoteChar . str_replace($this->QuoteChar, $this->QuoteChar . $this->QuoteChar, strval($val)) . $this->QuoteChar; }
then replace it with the following code:
class cExportCsv extends cExportBase { var $QuoteChar = "\""; // Style function ChangeStyle($style) { $this->Horizontal = TRUE; } // Table header function ExportTableHeader() { // Skip } // Export a value (caption, field value, or aggregate) function ExportValueEx(&$fld, $val, $usestyle = TRUE) { if ($this->Line <> "") $this->Line .= ";"; // replacing "comma" with "semicolon" character. $this->Line .= $this->QuoteChar . str_replace($this->QuoteChar, $this->QuoteChar . $this->QuoteChar, strval($val)) . $this->QuoteChar; }
- Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.