Beispiel #1
0
 /**
  * Convert string to UTF-8. Only used for BIFF5.
  *
  * @param string $string
  * @return string
  */
 private function _decodeCodepage($string)
 {
     $result = Shared_String::ConvertEncoding($string, 'UTF-8', $this->_codepage);
     return $result;
 }
Beispiel #2
0
 /**
  *	Loads PHPExcel from file into PHPExcel instance
  *
  *	@access	public
  *	@param 	string 		$pFilename
  *	@param	PHPExcel	$objPHPExcel
  *	@return 	PHPExcel
  *	@throws 	Exception
  */
 public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
 {
     // Check if file exists
     if (!file_exists($pFilename)) {
         throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
     }
     // Create new PHPExcel
     while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
         $objPHPExcel->createSheet();
     }
     $objPHPExcel->setActiveSheetIndex($this->_sheetIndex);
     // Open file
     $fileHandle = fopen($pFilename, 'r');
     if ($fileHandle === false) {
         throw new Exception("Could not open file {$pFilename} for reading.");
     }
     // Skip BOM, if any
     switch ($this->_inputEncoding) {
         case 'UTF-8':
             fgets($fileHandle, 4) == "" ? fseek($fileHandle, 3) : fseek($fileHandle, 0);
             break;
         default:
             break;
     }
     // Loop through file
     $currentRow = 0;
     $rowData = array();
     while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
         ++$currentRow;
         $rowDataCount = count($rowData);
         for ($i = 0; $i < $rowDataCount; ++$i) {
             $columnLetter = Cell::stringFromColumnIndex($i);
             if ($rowData[$i] != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
                 // Unescape enclosures
                 $rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
                 $rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
                 // Convert encoding if necessary
                 if ($this->_inputEncoding !== 'UTF-8') {
                     $rowData[$i] = Shared_String::ConvertEncoding($rowData[$i], 'UTF-8', $this->_inputEncoding);
                 }
                 // Set cell value
                 $objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
             }
         }
     }
     // Close file
     fclose($fileHandle);
     // Return
     return $objPHPExcel;
 }
Beispiel #3
0
 /**
  * Used to write internal reference hyperlinks such as "Sheet1!A1".
  *
  * @access private
  * @see _writeUrl()
  * @param integer $row1   Start row
  * @param integer $col1   Start column
  * @param integer $row2   End row
  * @param integer $col2   End column
  * @param string  $url	URL string
  * @return integer
  */
 function _writeUrlInternal($row1, $col1, $row2, $col2, $url)
 {
     $record = 0x1b8;
     // Record identifier
     $length = 0x0;
     // Bytes to follow
     // Strip URL type
     $url = preg_replace('/^internal:/', '', $url);
     // Pack the undocumented parts of the hyperlink stream
     $unknown1 = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
     // Pack the option flags
     $options = pack("V", 0x8);
     // Convert the URL type and to a null terminated wchar string
     $url .= "";
     // character count
     $url_len = Shared_String::CountCharacters($url);
     $url_len = pack('V', $url_len);
     $url = Shared_String::ConvertEncoding($url, 'UTF-16LE', 'UTF-8');
     // Calculate the data length
     $length = 0x24 + strlen($url);
     // Pack the header data
     $header = pack("vv", $record, $length);
     $data = pack("vvvv", $row1, $row2, $col1, $col2);
     // Write the packed data
     $this->_append($header . $data . $unknown1 . $options . $url_len . $url);
     return 0;
 }