diff --git a/php-export-data.class.php b/php-export-data.class.php index d983cf7..eda0aa7 100755 --- a/php-export-data.class.php +++ b/php-export-data.class.php @@ -39,6 +39,11 @@ public function initialize() { $this->write($this->generateHeader()); } + //added by Nicola Boccardi + public function addSheet($title){ + $this->write($this->generateSheet($title)); + } + public function addRow($row) { $this->write($this->generateRow($row)); } @@ -90,6 +95,11 @@ protected function generateFooter() { // can be overridden by subclass to return any data that goes at the bottom of the exported file } + //added by Nicola Boccardi + protected function generateSheet($title){ + // can be overridden by subclass to return a new sheet + } + // In subclasses generateRow will take $row array and return string of it formatted for export type abstract protected function generateRow($row); @@ -188,6 +198,19 @@ function generateFooter() { return $output; } + //added by Nicola Boccardi + function generateSheet($title){ + $output = ''; + $this->title = $title; + + // close previous worksheet + $output .= " \n\n"; + // open new worksheet with title + $output .= sprintf("\n \n", htmlentities($this->title)); + + return $output; + } + function generateRow($row) { $output = ''; $output .= " \n"; @@ -201,6 +224,7 @@ function generateRow($row) { private function generateCell($item) { $output = ''; $style = ''; + $formula = '';//added // Tell Excel to treat as a number. Note that Excel only stores roughly 15 digits, so keep // as text if number is longer than that. @@ -221,13 +245,19 @@ private function generateCell($item) { $item = strftime("%Y-%m-%dT%H:%M:%S",$timestamp); $style = 'sDT'; // defined in header; tells excel to format date for display } + //added by Nicola Boccardi + elseif(strpos($item, "=") === 0){ + $type = 'Number'; + $formula = sprintf("ss:Formula=\"%s\"", $item); + $item = ''; + } else { $type = 'String'; } $item = str_replace(''', ''', htmlspecialchars($item, ENT_QUOTES)); $output .= " "; - $output .= $style ? "" : ""; + $output .= $style ? "" : "";//modified $output .= sprintf("%s", $type, $item); $output .= "\n"; @@ -239,4 +269,4 @@ function sendHttpHeaders() { header("Content-Disposition: inline; filename=\"" . basename($this->filename) . "\""); } -} \ No newline at end of file +}