I am trying to use PHPexcel plugin to generate downloadable excel file from mysql data. Unfortunately, I am only getting only the column headers and not their values in the downloaded excel file
Where am I going wrong ? Also, I would like unicode characters to show properly.
Following is my code of the downloadexcel.php file -
<?php
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/Writer/Excel2007.php';
$objPHPExcel = new PHPExcel();
$data=array();
$sql="SELECT s.t_id,s.t_text,p.user_name,p.description,s.time,p.place from t
AS s INNER JOIN users AS p ON s.user_name=p.user_name order by s.time desc";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$array=array("T Link" => $row[0],"T"=>$row[1] , "User Name" => $row[2] ,
"User Profile" => $row[3], "Time" => $row[4] , "Place" => $row[5]);
array_push($data,$array);
}
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'T Link');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'T');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'User Name');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'User Profile');
$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Time');
$objPHPExcel->getActiveSheet()->setCellValue('F1', 'Place');
$row=2;
foreach($data as $row->$value) {
$objPHPExcel->getActiveSheet()->setCellValue('A'.$row,$value->t_id);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,$value->t_text);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$row,$value->user_name);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$row,$value->description);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$row,$value->time);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$row,$value->place);
$row++;
}
header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="helloworld.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
?>
Based on comments of Mark Baker, edited the code but still not getting any result. This is my edited code -
<?php
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/Writer/Excel2007.php';
$objPHPExcel = new PHPExcel();
$data=array();
$sql="SELECT s.t_id,s.t_text,p.user_name,p.description,s.time,p.place from t
AS s INNER JOIN users AS p ON s.user_name=p.user_name order by s.time desc";
$result = mysqli_query($con,$sql);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'T Link');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'T');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'User Name');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'User Profile');
$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Time');
$objPHPExcel->getActiveSheet()->setCellValue('F1', 'Place');
while ($row = mysqli_fetch_array($result))
{
$n=2;
foreach($data as $row) {
$objPHPExcel->getActiveSheet()->setCellValue('A'.$n,$row['t_id']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$n,$row['t_text']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$n,$row['user_name']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$n,$row['description']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$n,$row['time']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$n,$row['place']);
$n++;
}
}
header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="helloworld.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
?>
Change this line:
foreach($data as $row->$value) {
to
foreach($data as $row => $value) {
"->" operator is used with objects. The difference between the two operators is explained here: https://stackoverflow.com/a/14037376/577778
Updated Code
<?php
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/Writer/Excel2007.php';
$objPHPExcel = new PHPExcel();
$data=array();
$sql="SELECT s.t_id,s.t_text,p.user_name,p.description,s.time,p.place from t
AS s INNER JOIN users AS p ON s.user_name=p.user_name order by s.time desc";
$result = mysqli_query($con,$sql);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'T Link');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'T');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'User Name');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'User Profile');
$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Time');
$objPHPExcel->getActiveSheet()->setCellValue('F1', 'Place');
$n=2;
while ($row = mysqli_fetch_array($result))
{
$objPHPExcel->getActiveSheet()->setCellValue('A'.$n,$row['t_id']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$n,$row['t_text']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$n,$row['user_name']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$n,$row['description']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$n,$row['time']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$n,$row['place']);
$n++;
}
header('Content-Type: application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="helloworld.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
?>
Related
This how look generated excel file :
with the warning messages :
Message: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
Filename: Shared/OLE.php
This is comes in excel file -
þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ #€ÅfôíÖ#€ÅfôíÖþÿÕÍÕœ.“—+,ù®0¼HPX`hp
I have tried with iconv(mb_detect_encoding($result, mb_detect_order(), true), "UTF-8", $result); coversion as well.
This is the code :
public function exportExcel() {
$this->load->library('excel');
$registrationIDArr = $_POST["registrationID"];
$resigtrationIDStr = implode(",",$registrationIDArr);
$currDate = date("d-m-Y_H_i");
$file = 'VolunteerRegistration_'.$currDate.'.xls';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Volunteer Details');
$style = array('font' => array('size' => 12,'bold' => true));
$objPHPExcel->getActiveSheet()->getStyle('A1:B1')->applyFromArray($style);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Name');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Email');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$rows = 2;
$result = $this->getVolunteerDetailsForExcelExport($resigtrationIDStr);
foreach($result as $row){
$objPHPExcel->getActiveSheet()->setCellValue('A'.$rows, $row->name);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$rows, $row->email);
$rows++;
}
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$file.'"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
ob_start();
$objWriter->save('php://output');
exit;
}
public function getVolunteerDetailsForExcelExport($registrationIDStr){
$this->db->select("CONCAT(fname,' ',mname,' ',lname) AS name, email");
$this->db->from('UserRegistration');
$wherelist = "id in($registrationIDStr)";
$this->db->where($wherelist);
$query= $this->db->get();
$result = $query->result();
return $result;
}
In PHPExcel/Shared/OLE.php,function _readPpsWks($blockId), there is an error in the for / switch structure.
In the default case of the switch, you write continue;. But this does NOT exit the for loop. It only exits the "switch" structure, and continue under. You have to write: continue 2;, at line number 290.
default:
continue 2;
Please try this, it might helps. This works for me.
require 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
/*CODE for excel*/
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="file.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
I am using PHPExcel with mysql and MongoDB to export data in Excel .XLS file but only in 1 Column some Lines are not showing and some are showing in same Columns while exporting although all are shown when i use $print_() to check output in browser
Here is my PHP Code -
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->getActiveSheet();
$sheet->setCellValue('M1', 'Headline');
$objPHPExcel->getActiveSheet()->getStyle('M')->applyFromArray($styleArray);
$objPHPExcel->getActiveSheet()->getStyle('M')->getFont()->setUnderline(true);
if ($result['type'] == "WEB") {
$sheet->setCellValue('M' . ($results + 2), $result['headline']);
$sheet->getCell('M' . ($results + 2))->getHyperlink()->setUrl($result['url']);
$sheet->getCell('M' . ($results + 2))->getHyperlink()->setTooltip('Navigate to website');
}
and this is my output
output
I post here an example without link (you can edit my code):
$objPHPExcel = new PHPExcel();
$result = $db->query("SELECT * FROM YOURTABLE") or die(mysql_error());
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('M1', 'Headline');
$objPHPExcel->getActiveSheet()->getStyle("M1")->getFont()->setBold(true);
$rowCount = 2;
while($row = $result->fetch_assoc()){
$objPHPExcel->getActiveSheet()->SetCellValue('M'.$rowCount, mb_strtoupper($row['headline'],'UTF-8'));
$rowCount++;
}
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="you-file-name.xlsx"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
I an trying to export data to an Excel file using PHPExcel libraries with Cakephp 2.5.
My Codes :
<?php
App::import('Vendor', 'PHPExcel', array('file' => 'PHPExcel'.DS.'PHPExcel.php'));
App::import('Vendor', 'PHPExcel_IOFactory', array('file' => 'PHPExcel'.DS.'PHPExcel'.DS.'IOFactory.php'));
App::import('Vendor', 'PHPExcel_IOFactory', array('file' => 'PHPExcel'.DS.'PHPExcel'.DS.'Style.php'));
class LeadUploadController extends AppController {
public function exel_download($emp_id='')
{
$this->autoRender = false;
$this-> layout='ajax';
$objPHPExcel = new PHPExcel();
$serialnumber=0;
$tmparray =array("Sr.Number","Employee ID","Employee Name");
$sheet =array($tmparray);
$tmparray =array();
$serialnumber = $serialnumber + 1;
array_push($tmparray,$serialnumber);
$employeelogin = 'aa';
array_push($tmparray,$employeelogin);
$employeename = 'bb';
array_push($tmparray,$employeename);
array_push($sheet,$tmparray);
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="file.xlsx"');
$worksheet = $objPHPExcel->getActiveSheet();
foreach($sheet as $row => $columns) {
foreach($columns as $column => $data) {
$worksheet->setCellValueByColumnAndRow($column, $row + 1, $data);
}
}
$objPHPExcel->getActiveSheet()->getStyle("A1:I1")->getFont()->setBold(true);
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
}
}
The problem is the downloaded Excel file contain no any data it completely blank with an error "can not open the file because of file format or extension not valid ". Have not any idea what's wrong with these code.
The following code should work on xls extension.
$objPHPExcel = new PHPExcel();
$serialnumber=0;
$tmparray =array("Sr.Number","Employee ID","Employee Name");
$sheet =array($tmparray);
$tmparray =array();
$serialnumber = $serialnumber + 1;
array_push($tmparray,$serialnumber);
$employeelogin = 'aa';
array_push($tmparray,$employeelogin);
$employeename = 'bb';
array_push($tmparray,$employeename);
array_push($sheet,$tmparray);
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="file.xls"');
$worksheet = $objPHPExcel->getActiveSheet();
foreach($sheet as $row => $columns) {
foreach($columns as $column => $data) {
$worksheet->setCellValueByColumnAndRow($column, $row + 1, $data);
}
}
$objPHPExcel->getActiveSheet()->getStyle("A1:I1")->getFont()->setBold(true);
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
I am using codeigniter framework, in this I am creating excel file with MySQL data's. I need to create header table (ie, first loop) data's into first sheet, detail table (ie, second loop) data's into second sheet. Below I have given my code, this generating in same sheet with next next data's. Can any one give some ideas to solve this.
$out = '"S.no","HeaderID","InvoiceID","InvoiceNo","doc_no","InvoiceDate","PartyCode","doc_type","CurrencyID","Remarks","loc_amt","doc_amt"'."\r\n";
$i=1;
foreach($export_list as $d)
{
$out .= $i.',"'.$d->slsid.'","'.'0'.'","'.$d->reference_no.'","'.' '.'","'.$d->date.'","'.$d->customer_code.'","'.' '.'","'.' '.'","'.$d->internal_note.'","'.'0'.'","'.$d->total.'"'."\r\n";
$i++;
}
$out .= '"S.no","HeaderID","DetailID","ProductID","Description","Qty","loc_amt","doc_amt"'."\r\n";
$i=1;
foreach($export_detail as $d)
{
$out .= $i.',"'.$d->sale_id.'","'.$d->id.'","'.$d->product_code.'","'.' '.'","'.$d->quantity.'","'.'0'.'","'.$d->gross_total.'"'."\r\n";
$i++;
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=Users.xls');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $out;
exit;
Thanks in advance.
Yes have to download PHPExcel library for codeigniter.
I have some sample code which help you to work on PHPExcel.
function test_excel()
{
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('test worksheet');
$this->excel->getActiveSheet()->setCellValue('A1', 'User id');
$this->excel->getActiveSheet()->setCellValue('B1', 'User name');
$this->excel->getActiveSheet()->setCellValue('C1', 'Email');
$this->excel->getActiveSheet()->setCellValue('D1', 'Status');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
$query = $this->db->query("SELECT * FROM users");
$k=2;
foreach($query->result_array() as $row)
{
$this->excel->getActiveSheet()->setCellValue("A".$k, $row['USER_ID']);
$this->excel->getActiveSheet()->setCellValue("B".$k, $row['FIRST_NAME']);
$this->excel->getActiveSheet()->setCellValue("C".$k, $row['USER_EMAIL']);
$this->excel->getActiveSheet()->setCellValue("D".$k, $row['USER_TYPE_ID']);
$k++;
}
$filename='just_some_random_name.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');
}
Hope it will help you.
Hi #Jagan Akash check this,
public function test_excel()
{
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle('test worksheet');
$this->excel->getActiveSheet()->setCellValue('A1', 'User id');
$this->excel->getActiveSheet()->setCellValue('B1', 'User name');
$this->excel->getActiveSheet()->setCellValue('C1', 'Email');
$this->excel->getActiveSheet()->setCellValue('D1', 'Status');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
$query = $this->db->query("SELECT * FROM user limit 2");
$k=2;
foreach($query->result_array() as $row)
{
$this->excel->getActiveSheet()->setCellValue("A".$k, $row['user_id']);
$this->excel->getActiveSheet()->setCellValue("B".$k, $row['first_name']);
$this->excel->getActiveSheet()->setCellValue("C".$k, $row['last_name']);
$this->excel->getActiveSheet()->setCellValue("D".$k, $row['user_email']);
$k++;
}
$init_cnt = $this->excel->getSheetCount();
$this->excel->createSheet($init_cnt);
$this->excel->setActiveSheetIndex($init_cnt);
$this->excel->getActiveSheet()->setTitle('test 1');
$this->excel->getActiveSheet()->setCellValue('A1', '1');
$this->excel->getActiveSheet()->setCellValue('B1', '2');
$this->excel->getActiveSheet()->setCellValue('C1', '3');
$this->excel->getActiveSheet()->setCellValue('D1', '4');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
$query = $this->db->query("SELECT * FROM user limit 2,2");
$k=2;
foreach($query->result_array() as $row)
{
$this->excel->getActiveSheet()->setCellValue("A".$k, $row['user_id']);
$this->excel->getActiveSheet()->setCellValue("B".$k, $row['first_name']);
$this->excel->getActiveSheet()->setCellValue("C".$k, $row['last_name']);
$this->excel->getActiveSheet()->setCellValue("D".$k, $row['user_email']);
$k++;
}
$init_cnt = $this->excel->getSheetCount();
$this->excel->createSheet($init_cnt);
$this->excel->setActiveSheetIndex($init_cnt);
$this->excel->getActiveSheet()->setTitle('test 2');
$this->excel->getActiveSheet()->setCellValue('A1', '12');
$this->excel->getActiveSheet()->setCellValue('B1', '22');
$this->excel->getActiveSheet()->setCellValue('C1', '32');
$this->excel->getActiveSheet()->setCellValue('D1', '42');
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
$query = $this->db->query("SELECT * FROM user limit 4,2");
$k=2;
foreach($query->result_array() as $row)
{
$this->excel->getActiveSheet()->setCellValue("A".$k, $row['user_id']);
$this->excel->getActiveSheet()->setCellValue("B".$k, $row['first_name']);
$this->excel->getActiveSheet()->setCellValue("C".$k, $row['last_name']);
$this->excel->getActiveSheet()->setCellValue("D".$k, $row['user_email']);
$k++;
}
$this->excel->setActiveSheetIndex(0);
$filename='just_some_random_name.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');
}
This will give answer to all question.
I'm using PHPExcel to generate a listing.
The problem is that the text overflows the width of the cell B.
How do I place a fixed width and length automatic, so that it does not overflow ?
Attachment:
Code:
$objPHPExcel = new PHPExcel();
$objPHPExcel->
getProperties()
->setCreator("TEDnologia.com")
->setLastModifiedBy("TEDnologia.com")
->setTitle("Exportar Excel con PHP")
->setSubject("Documento de prueba")
->setDescription("Documento generado con PHPExcel")
->setKeywords("usuarios phpexcel")
->setCategory("reportes");
$query = mysql_query('select * from articulos');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Nombre')
->setCellValue('B1', 'E-mail')
->setCellValue('C1', 'E-mail')
;
$i=2;
while($row = mysql_fetch_assoc($query)){
$xx = "A".$i;
$xxx = "B".$i;
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($xx, $row["cod"])
->setCellValue($xxx, $row["descripcion"]);
;
$xxxx = "C".$i;
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('archivos/articulos/'.$row["imagen"].'');
$objDrawing->setCoordinates($xxxx);
$objDrawing->setHeight(36);
$objDrawing->setWidth(36);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$i++;
}
$objPHPExcel->getActiveSheet()->setTitle('Usuarios');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
$objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true);