30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
38 require_once PHPEXCEL_ROOT .
'PHPExcel/Writer/IWriter.php';
41 require_once PHPEXCEL_ROOT .
'PHPExcel/Cell.php';
44 require_once PHPEXCEL_ROOT .
'PHPExcel/RichText.php';
47 require_once PHPEXCEL_ROOT .
'PHPExcel/Shared/String.php';
113 $this->_phpExcel = $phpExcel;
114 $this->_delimiter =
',';
115 $this->_enclosure =
'"';
116 $this->_lineEnding = PHP_EOL;
117 $this->_sheetIndex = 0;
126 public function save($pFilename = null) {
128 $sheet = $this->_phpExcel->getSheet($this->_sheetIndex);
134 $fileHandle = fopen($pFilename,
'w');
135 if ($fileHandle ===
false) {
136 throw new Exception(
"Could not open file $pFilename for writing.");
139 if ($this->_useBOM) {
141 fwrite($fileHandle,
"\xEF\xBB\xBF");
145 $cellsArray = $sheet->toArray(
'', $this->_preCalculateFormulas);
148 foreach ($cellsArray as
$row) {
174 $this->_delimiter = $pValue;
197 $this->_enclosure = $pValue;
217 $this->_lineEnding = $pValue;
237 $this->_useBOM = $pValue;
257 $this->_sheetIndex = $pValue;
268 private function _writeLine($pFileHandle = null, $pValues = null) {
269 if (!is_null($pFileHandle) && is_array($pValues)) {
271 $writeDelimiter =
false;
276 foreach ($pValues as $element) {
278 $element = str_replace($this->_enclosure, $this->_enclosure . $this->_enclosure, $element);
281 if ($writeDelimiter) {
284 $writeDelimiter =
true;
295 fwrite($pFileHandle, $line);
297 throw new Exception(
"Invalid parameters passed.");
317 $this->_preCalculateFormulas = $pValue;