30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
98 if (!file_exists($pFilename)) {
99 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
103 $fh = fopen($pFilename,
'r');
104 $data = fread($fh, 2048);
108 $delimiterCount = substr_count(
$data,
';');
109 if ($delimiterCount < 1) {
114 $lines = explode(
"\n",
$data);
115 if (substr($lines[0],0,4) !=
'ID;P') {
129 public function load($pFilename)
153 $this->_readFilter = $pValue;
164 $this->_inputEncoding = $pValue;
189 if (!file_exists($pFilename)) {
190 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
199 $fromFormats = array(
'\-',
'\ ');
200 $toFormats = array(
'-',
' ');
203 $fileHandle = fopen($pFilename,
'r');
204 if ($fileHandle ===
false) {
205 throw new Exception(
"Could not open file $pFilename for reading.");
213 while (($rowData = fgets($fileHandle)) !== FALSE) {
220 $rowData = explode(
"\t",str_replace(
'¤',
';',str_replace(
';',
"\t",str_replace(
';;',
'¤',rtrim($rowData)))));
222 $dataType = array_shift($rowData);
224 if ($dataType ==
'P') {
225 $formatArray = array();
226 foreach($rowData as $rowDatum) {
227 switch($rowDatum{0}) {
228 case 'P' : $formatArray[
'numberformat'][
'code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1));
231 case 'F' : $formatArray[
'font'][
'name'] = substr($rowDatum,1);
233 case 'L' : $formatArray[
'font'][
'size'] = substr($rowDatum,1);
235 case 'S' : $styleSettings = substr($rowDatum,1);
236 for ($i=0;$i<strlen($styleSettings);++$i) {
237 switch ($styleSettings{$i}) {
238 case 'I' : $formatArray[
'font'][
'italic'] =
true;
240 case 'D' : $formatArray[
'font'][
'bold'] =
true;
255 $this->_formats[
'P'.$this->_format++] = $formatArray;
257 } elseif ($dataType ==
'C') {
258 $hasCalculatedValue =
false;
259 $cellData = $cellDataFormula =
'';
260 foreach($rowData as $rowDatum) {
261 switch($rowDatum{0}) {
263 case 'X' : $column = substr($rowDatum,1);
266 case 'Y' :
$row = substr($rowDatum,1);
268 case 'K' : $cellData = substr($rowDatum,1);
270 case 'E' : $cellDataFormula =
'='.substr($rowDatum,1);
272 $temp = explode(
'"',$cellDataFormula);
274 foreach($temp as &$value) {
277 preg_match_all(
'/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
281 $cellReferences = array_reverse($cellReferences);
284 foreach($cellReferences as $cellReference) {
285 $rowReference = $cellReference[2][0];
287 if ($rowReference ==
'') $rowReference =
$row;
289 if ($rowReference{0} ==
'[') $rowReference =
$row + trim($rowReference,
'[]');
290 $columnReference = $cellReference[4][0];
292 if ($columnReference ==
'') $columnReference = $column;
294 if ($columnReference{0} ==
'[') $columnReference = $column + trim($columnReference,
'[]');
297 $value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
303 $cellDataFormula = implode(
'"',$temp);
304 $hasCalculatedValue =
true;
312 $objPHPExcel->
getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
313 if ($hasCalculatedValue) {
315 $objPHPExcel->
getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
318 } elseif ($dataType ==
'F') {
319 $formatStyle = $columnWidth = $styleSettings =
'';
320 $styleData = array();
321 foreach($rowData as $rowDatum) {
322 switch($rowDatum{0}) {
324 case 'X' : $column = substr($rowDatum,1);
327 case 'Y' :
$row = substr($rowDatum,1);
329 case 'P' : $formatStyle = $rowDatum;
331 case 'W' : list($startCol,$endCol,$columnWidth) = explode(
' ',substr($rowDatum,1));
333 case 'S' : $styleSettings = substr($rowDatum,1);
334 for ($i=0;$i<strlen($styleSettings);++$i) {
335 switch ($styleSettings{$i}) {
336 case 'I' : $styleData[
'font'][
'italic'] =
true;
338 case 'D' : $styleData[
'font'][
'bold'] =
true;
353 if (($formatStyle >
'') && ($column >
'') && (
$row >
'')) {
355 $objPHPExcel->
getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
357 if ((count($styleData) > 0) && ($column >
'') && (
$row >
'')) {
359 $objPHPExcel->
getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
361 if ($columnWidth >
'') {
362 if ($startCol == $endCol) {
364 $objPHPExcel->
getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
368 $objPHPExcel->
getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
370 $objPHPExcel->
getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
371 }
while ($startCol != $endCol);
375 foreach($rowData as $rowDatum) {
376 switch($rowDatum{0}) {
378 case 'X' : $column = substr($rowDatum,1);
381 case 'Y' :
$row = substr($rowDatum,1);
411 $this->_sheetIndex = $pValue;