PHPExcel renames worksheet name by another name

I use PHPExcel to export my files from the database, but my problem is that when I load my excel, the name of my sheet is the default sheet. I would like to install it under another name, for example "Hello world".

Here is my code so far

require_once dirname(__FILE__) . '/Classes/PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '1') ->setCellValue('B1', '2') ->setCellValue('C1', '3') ->setCellValue('D1', '4') ->setCellValue('E1', '5') ->setCellValue('F1', '6') ->setCellValue('G1', '7') ->setCellValue('H1', '8') ->setCellValue('I1', '9') ->setCellValue('J1', '10'); $row = 2; while($rowz = $result->fetch(PDO::FETCH_ASSOC)) { $col = 0; foreach($rowz as $key=>$value) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value); $col++; } $row++; } 

How can I set a new title for my worksheet? Thanks!

+8
php excel phpexcel
source share
2 answers

You can set the title like this:

 $objPHPExcel->getActiveSheet()->setTitle("Title"); 
+13
source share

Try using this code to rename excel file

 header ('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header ('Content-Disposition: attachment;filename="hello_world.xlsx"'); header ('Cache-Control: max-age=0'); 
+1
source share

All Articles