30 if (!
defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
90 $data = fread($this->_fileHandle, 2048);
93 $delimiterCount = substr_count(
$data,
';');
94 if ($delimiterCount < 1) {
99 $lines = explode(
"\n",
$data);
100 if (substr($lines[0],0,4) !=
'ID;P') {
114 $this->_inputEncoding = $pValue;
139 fclose ($this->_fileHandle);
145 $worksheetInfo =
array();
146 $worksheetInfo[0][
'worksheetName'] =
'Worksheet';
147 $worksheetInfo[0][
'lastColumnLetter'] =
'A';
148 $worksheetInfo[0][
'lastColumnIndex'] = 0;
149 $worksheetInfo[0][
'totalRows'] = 0;
150 $worksheetInfo[0][
'totalColumns'] = 0;
157 while (($rowData = fgets($fileHandle)) !== FALSE) {
165 $rowData = explode(
"\t",str_replace(
'¤',
';',str_replace(
';',
"\t",str_replace(
';;',
'¤',rtrim($rowData)))));
167 $dataType = array_shift($rowData);
168 if ($dataType ==
'C') {
170 foreach($rowData as $rowDatum) {
171 switch($rowDatum{0}) {
174 $columnIndex = substr($rowDatum,1) - 1;
178 $rowIndex = substr($rowDatum,1);
182 $worksheetInfo[0][
'totalRows'] = max($worksheetInfo[0][
'totalRows'], $rowIndex);
183 $worksheetInfo[0][
'lastColumnIndex'] = max($worksheetInfo[0][
'lastColumnIndex'], $columnIndex);
189 $worksheetInfo[0][
'totalColumns'] = $worksheetInfo[0][
'lastColumnIndex'] + 1;
194 return $worksheetInfo;
204 public function load($pFilename)
226 fclose ($this->_fileHandle);
238 $fromFormats =
array(
'\-',
'\ ');
239 $toFormats =
array(
'-',
' ');
246 while (($rowData = fgets($fileHandle)) !== FALSE) {
253 $rowData = explode(
"\t",str_replace(
'¤',
';',str_replace(
';',
"\t",str_replace(
';;',
'¤',rtrim($rowData)))));
255 $dataType = array_shift($rowData);
257 if ($dataType ==
'P') {
258 $formatArray =
array();
259 foreach($rowData as $rowDatum) {
260 switch($rowDatum{0}) {
261 case 'P' : $formatArray[
'numberformat'][
'code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1));
264 case 'F' : $formatArray[
'font'][
'name'] = substr($rowDatum,1);
266 case 'L' : $formatArray[
'font'][
'size'] = substr($rowDatum,1);
268 case 'S' : $styleSettings = substr($rowDatum,1);
269 for ($i=0;$i<strlen($styleSettings);++$i) {
270 switch ($styleSettings{$i}) {
271 case 'I' : $formatArray[
'font'][
'italic'] =
true;
273 case 'D' : $formatArray[
'font'][
'bold'] =
true;
288 $this->_formats[
'P'.$this->_format++] = $formatArray;
290 } elseif ($dataType ==
'C') {
291 $hasCalculatedValue =
false;
292 $cellData = $cellDataFormula =
'';
293 foreach($rowData as $rowDatum) {
294 switch($rowDatum{0}) {
296 case 'X' :
$column = substr($rowDatum,1);
299 case 'Y' :
$row = substr($rowDatum,1);
301 case 'K' : $cellData = substr($rowDatum,1);
303 case 'E' : $cellDataFormula =
'='.substr($rowDatum,1);
305 $temp = explode(
'"',$cellDataFormula);
307 foreach($temp as &$value) {
310 preg_match_all(
'/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
314 $cellReferences = array_reverse($cellReferences);
317 foreach($cellReferences as $cellReference) {
318 $rowReference = $cellReference[2][0];
320 if ($rowReference ==
'') $rowReference =
$row;
322 if ($rowReference{0} ==
'[') $rowReference =
$row + trim($rowReference,
'[]');
323 $columnReference = $cellReference[4][0];
325 if ($columnReference ==
'') $columnReference =
$column;
327 if ($columnReference{0} ==
'[') $columnReference =
$column + trim($columnReference,
'[]');
330 $value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
336 $cellDataFormula = implode(
'"',$temp);
337 $hasCalculatedValue =
true;
345 $objPHPExcel->
getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
346 if ($hasCalculatedValue) {
348 $objPHPExcel->
getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
351 } elseif ($dataType ==
'F') {
352 $formatStyle = $columnWidth = $styleSettings =
'';
353 $styleData =
array();
354 foreach($rowData as $rowDatum) {
355 switch($rowDatum{0}) {
357 case 'X' :
$column = substr($rowDatum,1);
360 case 'Y' :
$row = substr($rowDatum,1);
362 case 'P' : $formatStyle = $rowDatum;
364 case 'W' : list($startCol,$endCol,$columnWidth) = explode(
' ',substr($rowDatum,1));
366 case 'S' : $styleSettings = substr($rowDatum,1);
367 for ($i=0;$i<strlen($styleSettings);++$i) {
368 switch ($styleSettings{$i}) {
369 case 'I' : $styleData[
'font'][
'italic'] =
true;
371 case 'D' : $styleData[
'font'][
'bold'] =
true;
386 if (($formatStyle >
'') && (
$column >
'') && (
$row >
'')) {
388 if (isset($this->_formats[$formatStyle])) {
389 $objPHPExcel->
getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
392 if ((!empty($styleData)) && (
$column >
'') && (
$row >
'')) {
394 $objPHPExcel->
getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
396 if ($columnWidth >
'') {
397 if ($startCol == $endCol) {
399 $objPHPExcel->
getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
403 $objPHPExcel->
getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
405 $objPHPExcel->
getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
406 }
while ($startCol != $endCol);
410 foreach($rowData as $rowDatum) {
411 switch($rowDatum{0}) {
413 case 'X' :
$column = substr($rowDatum,1);
416 case 'Y' :
$row = substr($rowDatum,1);
446 $this->_sheetIndex = $pValue;
__construct()
Create a new PHPExcel_Reader_SYLK.
getSheetCount()
Get sheet count.
loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
Loads PHPExcel from file into PHPExcel instance.
setSheetIndex($pValue=0)
Set sheet index.
listWorksheetInfo($pFilename)
Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) ...
createSheet($iSheetIndex=NULL)
Create sheet and add it to this workbook.
_isValidFormat()
Validate that the current file is a SYLK file.
setInputEncoding($pValue='ANSI')
Set input encoding.
getInputEncoding()
Get input encoding.
Create styles array
The data for the language used.
getSheetIndex()
Get sheet index.
getActiveSheet()
Get active sheet.
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
setActiveSheetIndex($pIndex=0)
Set active sheet index.
static _unwrapResult($value)
Remove quotes used as a wrapper to identify string values.
_openFile($pFilename)
Open file for reading.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
static SYLKtoUTF8($pValue='')
Convert SYLK encoded string to UTF-8.
load($pFilename)
Loads PHPExcel from file.