I have an array which contains data as:
array(name,contact1,e_mail ,reference_type,resume_source,current_employer,highest_degree ,skill_set,track)

now i want to create an excel sheet(.xls file). In short I want to generate a reropt for query.

Array is nothing but the query result.
I want to just put this data rows into excel sheet.

How can do this in PHP?

Hello,

<?php
$filename ="excelreport.xls";
$contents = "testdata1 \t testdata2 \t testdata3 \t \n";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $contents;
?>

is not working for me.
It is giving some boxes characters.
was should I set in headers in charset?

You can also try this.. Please let me know if there is an error.. I barely updated the script from 2 years ago..The original author never released an update ever since.

Here is an example on how to use it..(lifted from the original author's distros)

$xls = new Excel('Report');
foreach ($rows as $num => $row) {
  $xls->home();
  $xls->label($row['id']);
  $xls->right();
  $xls->label($row['title']);
  $xls->down();
}
ob_start();
$data = ob_get_clean();
file_put_contents(__DIR__ .'/report.xls', $data);

The $rows is the array, it could be from database or just plain text..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.