当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Shared_String::SYLKtoUTF8方法代码示例

本文整理汇总了PHP中PHPExcel_Shared_String::SYLKtoUTF8方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_String::SYLKtoUTF8方法的具体用法?PHP PHPExcel_Shared_String::SYLKtoUTF8怎么用?PHP PHPExcel_Shared_String::SYLKtoUTF8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Shared_String的用法示例。


在下文中一共展示了PHPExcel_Shared_String::SYLKtoUTF8方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadIntoExisting

 /**
  * Loads PHPExcel from file into PHPExcel instance
  *
  * @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);
     $fromFormats = array('\\-', '\\ ');
     $toFormats = array('-', ' ');
     // Open file
     $fileHandle = fopen($pFilename, 'r');
     if ($fileHandle === false) {
         throw new Exception("Could not open file {$pFilename} for reading.");
     }
     // Loop through file
     $rowData = array();
     $column = $row = '';
     // loop through one row (line) at a time in the file
     while (($rowData = fgets($fileHandle)) !== FALSE) {
         // convert SYLK encoded $rowData to UTF-8
         $rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);
         // explode each row at semicolons while taking into account that literal semicolon (;)
         // is escaped like this (;;)
         $rowData = explode("\t", str_replace('¤', ';', str_replace(';', "\t", str_replace(';;', '¤', rtrim($rowData)))));
         $dataType = array_shift($rowData);
         //	Read shared styles
         if ($dataType == 'P') {
             $formatArray = array();
             foreach ($rowData as $rowDatum) {
                 switch ($rowDatum[0]) {
                     case 'P':
                         $formatArray['numberformat']['code'] = str_replace($fromFormats, $toFormats, substr($rowDatum, 1));
                         break;
                     case 'E':
                     case 'F':
                         $formatArray['font']['name'] = substr($rowDatum, 1);
                         break;
                     case 'L':
                         $formatArray['font']['size'] = substr($rowDatum, 1);
                         break;
                     case 'S':
                         $styleSettings = substr($rowDatum, 1);
                         for ($i = 0; $i < strlen($styleSettings); ++$i) {
                             switch ($styleSettings[$i]) {
                                 case 'I':
                                     $formatArray['font']['italic'] = true;
                                     break;
                                 case 'D':
                                     $formatArray['font']['bold'] = true;
                                     break;
                                 case 'T':
                                     $formatArray['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
                                     break;
                                 case 'B':
                                     $formatArray['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
                                     break;
                                 case 'L':
                                     $formatArray['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
                                     break;
                                 case 'R':
                                     $formatArray['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
                                     break;
                             }
                         }
                         break;
                 }
             }
             $this->_formats['P' . $this->_format++] = $formatArray;
             //	Read cell value data
         } elseif ($dataType == 'C') {
             $hasCalculatedValue = false;
             $cellData = $cellDataFormula = '';
             foreach ($rowData as $rowDatum) {
                 switch ($rowDatum[0]) {
                     case 'C':
                     case 'X':
                         $column = substr($rowDatum, 1);
                         break;
                     case 'R':
                     case 'Y':
                         $row = substr($rowDatum, 1);
                         break;
                     case 'K':
                         $cellData = substr($rowDatum, 1);
                         break;
                     case 'E':
                         $cellDataFormula = '=' . substr($rowDatum, 1);
                         //	Convert R1C1 style references to A1 style references (but only when not quoted)
//.........这里部分代码省略.........
开发者ID:hcvcastro,项目名称:pxp,代码行数:101,代码来源:SYLK.php


注:本文中的PHPExcel_Shared_String::SYLKtoUTF8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。