Hi all,
I am using the next code to change database data into excel sheet.
<?php
function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// file name for download
$filename = "OBR_Recettes" . time() . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
$result = mysqli_query($conn, $sql ) or die('Query failed !: '.mysqli_error($conn));
while($row = mysqli_fetch_assoc($result)) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\n";
}
?>
$result is computed from $sql query.
Problem of this, it is giving a warning when file opens with Excel 2007 and i cannot customize it.
Now, i saw a very powerful Excel Class, called PHPExcel from www.codeplex.com. This one is really
very powerful. But the major drawback, i saw no usage example or tutorial for this. Does someone know how to start off in using this PHPExcel class? (Example or tuto)
Thanks in advance.