1 3
2 4
entonces me genera el csv
1;3
2;4
**************************
pero falla cuando el excel vien asi
1 3 5 7
2 (celda vacia) 6 8
deveria
arrojarme
1;3;5;7
2; ;6;8
cuandoes unaespacio vacio noloconsidera ,dandome unresultado asi
1;3;5;7
2;6;8
este es mi script cualquier ayuda gracias
<?php
//*crear el csv
$csv_end = "\n";
$csv_sep = ";";
$csv_file = "espacio2.csv";
$csv="";
//*
require_once 'CompoundDocument.inc.php';
require_once 'BiffWorkbook.inc.php';
$fileName = 'espacio.xls';
if (!is_readable ($fileName)) die ('Cannot read ' . $fileName);
$doc = new CompoundDocument ('utf-8');
$doc->parse (file_get_contents ($fileName));
$wb = new BiffWorkbook ($doc);
$wb->parse ();
foreach ($wb->sheets as $sheetName => $sheet)
{
'<h1>' . $sheetName . '</h1>';
'<table cellspacing = "0">';
for ($row = 0; $row < $sheet->rows (); $row ++)
{
'<tr>';
for ($col = 0; $col < $sheet->cols (); $col ++)
{
if (!isset ($sheet->cells [$row][$col])) continue;
$cell = $sheet->cells [$row][$col];
'<td style = "' . $cell->style->css () . '" rowspan = "' . $cell->rowspan . '" colspan = "' . $cell->colspan . '">';
is_null ($cell->value) ? ' ' : $cell->value;
$csv.=$cell->value.$csv_sep;
'</td>';
}
$csv.=$csv_end;
$csv = substr($csv, 0, -2).$csv_end;
'</tr>';
}
'</table>';
}
//creando el csv
if (!$handle = fopen($csv_file, "w")) {
echo "Cannot open file";
exit;
}
if (fwrite($handle, utf8_decode($csv)) === FALSE) {
echo "Cannot write to file";
exit;
}
fclose($handle);
?>