4
* Provides entity phone helper functions and inherits several methods and properties from the
9
* LICENSE: This source file is subject to LGPLv2.1 license
10
* that is available through the world-wide-web at the following URI:
11
* http://www.gnu.org/licenses/lgpl-2.1.html
13
* Based on the work of Simple excel writer class
16
* @link https://gist.github.com/929039
18
* @author Clayton Kramer, CUNY SPS
20
* Copyright of the Sahana Software Foundation, sahanafoundation.org
22
class agExcel2003ExportHelper
31
* Safely encode a string for use as a filename
32
* @param string $title The title to use for the file
33
* @return string The file safe title
35
static function filename($title)
37
$result = strtolower(trim($title));
38
$result = str_replace("'", '', $result);
39
$result = preg_replace('#[^a-z0-9_]+#', '-', $result);
40
$result = preg_replace('#\-{2,}#', '-', $result);
41
return preg_replace('#(^\-+|\-+$)#D', '', $result);
45
* Builds a new Excel Spreadsheet object
46
* @return Excel The Spreadsheet
48
function __construct($title)
50
$this->title = $title;
58
* Transmits the proper headers to cause a download to occur and to identify the file properly
63
header("Content-Type: application/force-download");
64
header("Content-Type: application/octet-stream");
65
header("Content-Type: application/download");
66
header("Content-Disposition: attachment;filename=" . Excel::filename($this->title) . ".xls ");
67
header("Content-Transfer-Encoding: binary ");
71
* Streams the data to the browser
82
* Saves XLS file to a file path location
89
$fh = fopen($file, 'w') or die("Error: can't open $file for writing.\n");
90
fwrite($fh, $this->data);
95
* Writes the Excel Beginning of File marker
99
private function bofMarker()
101
$this->data .= pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
105
* Writes the Excel End of File marker
109
private function eofMarker()
111
$this->data .= pack("ss", 0x0A, 0x00);
115
* Moves internal cursor left by the amount specified
116
* @param optional integer $amount The amount to move left by, defaults to 1
117
* @return integer The current column after the move
119
function left($amount = 1)
121
$this->col -= $amount;
122
if ($this->col < 0) {
129
* Moves internal cursor right by the amount specified
130
* @param optional integer $amount The amount to move right by, defaults to 1
131
* @return integer The current column after the move
133
function right($amount = 1)
135
$this->col += $amount;
140
* Moves internal cursor up by amount
141
* @param optional integer $amount The amount to move up by, defaults to 1
142
* @return integer The current row after the move
144
function up($amount = 1)
146
$this->row -= $amount;
147
if ($this->row < 0) {
154
* Moves internal cursor down by amount
155
* @param optional integer $amount The amount to move down by, defaults to 1
156
* @return integer The current row after the move
158
function down($amount = 1)
160
$this->row += $amount;
165
* Moves internal cursor to the top of the page, row = 0
174
* Moves internal cursor all the way left, col = 0
183
* Writes a number to the Excel Spreadsheet
185
* @param integer $value The value to write out
188
function number($value)
190
$this->data .= pack("sssss", 0x203, 14, $this->row, $this->col, 0x0);
191
$this->data .= pack("d", $value);
195
* Writes a string (or label) to the Excel Spreadsheet
197
* @param string $value The value to write out
200
function label($value)
202
$length = strlen($value);
203
$this->data .= pack("ssssss", 0x204, 8 + $length, $this->row, $this->col, 0x0, $length);
204
$this->data .= $value;
208
* Get's the current row number
b'\\ No newline at end of file'