Add saveAllSheets to CSV Writer?

Topics: Developer Forum
May 10, 2011 at 10:13 PM

would it be possible to add this to the PHPExcel_Writer_CSV?

	public function saveAllSheets($pFilename = null,$use_states=array('visible')) {
		$saveDebugLog = PHPExcel_Calculation::getInstance()->writeDebugLog;
		PHPExcel_Calculation::getInstance()->writeDebugLog = false;
		$saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
		PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);

		// Open file
		$fileHandle = fopen($pFilename, 'wb+');
		if ($fileHandle === false) {
			throw new Exception("Could not open file $pFilename for writing.");
		}

		if ($this->_useBOM) {
			// Write the UTF-8 BOM code
			fwrite($fileHandle, "\xEF\xBB\xBF");
		}

		foreach ($this->_phpExcel->getWorksheetIterator() as $i=>$worksheet) {
			$wtitle = $worksheet->getTitle();
			//echo $i.' - ' . $wtitle . "\n<br/>";
			$wstate = $worksheet->getSheetState();
			//echo '- ' . $wstate . "\n<br/>";
			if(in_array($wstate,$use_states)){
				//echo " - Processing\n<br/>";

				// get the worksheet.
				$sheet = $this->_phpExcel->getSheet($i);
				// Convert sheet to array
				$cellsArray = $sheet->toArray('', $this->_preCalculateFormulas);
				//var_dump($cellsArray);

				// Write rows to file
				foreach ($cellsArray as $row) {
					$this->_writeLine($fileHandle, $row);
				}

			} else {
				//echo " - NOT using this sheet\n<br/>";
			}
		}
		// Close file
		fclose($fileHandle);

		PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
		PHPExcel_Calculation::getInstance()->writeDebugLog = $saveDebugLog;
	}