Skip to content
This repository was archived by the owner on Jun 6, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion php-export-data.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ abstract class ExportData {
protected $stringData; // stringData so far, used if export string mode
protected $tempFile; // handle to temp file (for export file mode)
protected $tempFilename; // temp file name and path (for export file mode)
protected $thousandsSeparator; // handle thousands separator in excel export

public $filename; // file mode: the output file name; browser mode: file name for download; string mode: not used

public function __construct($exportTo = "browser", $filename = "exportdata") {
public function __construct($exportTo = "browser", $filename = "exportdata", $thousandsSeparator = false) {
if(!in_array($exportTo, array('browser','file','string') )) {
throw new Exception("$exportTo is not a valid ExportData export type");
}
$this->exportTo = $exportTo;
$this->filename = $filename;
$this->thousandsSeparator = $thousandsSeparator;
}

public function initialize() {
Expand Down Expand Up @@ -168,6 +170,7 @@ function generateHeader() {
// Set up styles
$output .= "<Styles>\n";
$output .= "<Style ss:ID=\"sDT\"><NumberFormat ss:Format=\"Short Date\"/></Style>\n";
$output .= "<Style ss:ID=\"s63\"><NumberFormat ss:Format=\"Standard\"/></Style>\n";
$output .= "</Styles>\n";

// worksheet header
Expand Down Expand Up @@ -206,6 +209,7 @@ private function generateCell($item) {
// as text if number is longer than that.
if(preg_match("/^-?\d+(?:[.,]\d+)?$/",$item) && (strlen($item) < 15)) {
$type = 'Number';
$style = $this->thousandsSeparator ? 's63' : null; // defined in header; tells excel to format number with thousands separator
}
// Sniff for valid dates; should look something like 2010-07-14 or 7/14/2010 etc. Can
// also have an optional time after the date.
Expand Down