コード例 #1
0
ファイル: Excel5.php プロジェクト: electromanlord/sgd
 /**
  * Save PHPExcel to file
  *
  * @param	string		$pFileName
  * @throws	Exception
  */
 public function save($pFilename = null)
 {
     $phpExcel = $this->_phpExcel;
     $workbook = new PHPExcel_Writer_Excel5_Workbook($pFilename, $phpExcel);
     $workbook->setVersion(8);
     // Set temp dir
     if ($this->_tempDir != '') {
         $workbook->setTempDir($this->_tempDir);
     }
     $saveDateReturnType = PHPExcel_Calculation_Functions::getReturnDateType();
     PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
     // Add 15 style Xf's plus 1 cell Xf. Why?
     for ($i = 0; $i < 15; ++$i) {
         $workbook->addXfWriter($phpExcel->getSheet(0)->getDefaultStyle(), true);
     }
     $workbook->addXfWriter($phpExcel->getSheet(0)->getDefaultStyle());
     // Style dictionary
     $xfIndexes = array();
     $allStyles = $this->_allStyles($this->_phpExcel);
     $cellStyleHashes = new PHPExcel_HashTable();
     $cellStyleHashes->addFromSource($allStyles);
     $addedStyles = array();
     foreach ($allStyles as $style) {
         $styleHashIndex = $style->getHashIndex();
         if (isset($addedStyles[$styleHashIndex])) {
             continue;
         }
         // mapping between PHPExcel style hash index and BIFF XF index
         $xfIndexes[$styleHashIndex] = $workbook->addXfWriter($style);
         $addedStyles[$style->getHashIndex()] = true;
     }
     // Add empty sheets
     foreach ($phpExcel->getSheetNames() as $sheetIndex => $sheetName) {
         $phpSheet = $phpExcel->getSheet($sheetIndex);
         $worksheet = $workbook->addWorksheet($phpSheet, $xfIndexes);
     }
     PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType);
     $workbook->close();
 }