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);
getSheetCount()
Get sheet count.
createSheet($iSheetIndex=NULL)
Create sheet and add it to this workbook.
_isValidFormat()
Validate that the current file is a SYLK file.
Create styles array
The data for the language used.
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.
static SYLKtoUTF8($pValue='')
Convert SYLK encoded string to UTF-8.