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
34 changes: 32 additions & 2 deletions php-export-data.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -188,6 +198,19 @@ function generateFooter() {
return $output;
}

//added by Nicola Boccardi
function generateSheet($title){
$output = '';
$this->title = $title;

// close previous worksheet
$output .= " </Table>\n</Worksheet>\n";
// open new worksheet with title
$output .= sprintf("<Worksheet ss:Name=\"%s\">\n <Table>\n", htmlentities($this->title));

return $output;
}

function generateRow($row) {
$output = '';
$output .= " <Row>\n";
Expand All @@ -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.
Expand All @@ -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('&#039;', '&apos;', htmlspecialchars($item, ENT_QUOTES));
$output .= " ";
$output .= $style ? "<Cell ss:StyleID=\"$style\">" : "<Cell>";
$output .= $style ? "<Cell ss:StyleID=\"$style\" $formula>" : "<Cell $formula>";//modified
$output .= sprintf("<Data ss:Type=\"%s\">%s</Data>", $type, $item);
$output .= "</Cell>\n";

Expand All @@ -239,4 +269,4 @@ function sendHttpHeaders() {
header("Content-Disposition: inline; filename=\"" . basename($this->filename) . "\"");
}

}
}