0

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?

4
Contributors
4
Replies
31
Views
4 Years
Discussion Span
Last Post by iamthwee
0

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?

0

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..

Edited by veedeoo: info added

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.