Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel renaming default worksheet name to another name

I am using PHPExcel to export my files from database, but my problem is when I download my excel the name of my sheet is the default "Worksheet". I would like to set it to another name like "Hello world".

Here's 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 am I able to set the new title for my worksheet? Thanks!

like image 461
user3796899 Avatar asked Mar 18 '16 06:03

user3796899


1 Answers

You can set the title like so:

$objPHPExcel->getActiveSheet()->setTitle("Title");
like image 78
skrilled Avatar answered Oct 16 '22 04:10

skrilled