Add 2 sheet

Topics: User Forum
Nov 2, 2010 at 1:45 PM

Hello,

I use the code from the example 01simple-download-xls.php version 1.7.4
How can I easily add a second sheet?

 

$objPHPExcel->setActiveSheetIndex(1)
            ->setCellValue('A1', 'Veranstaltungsnummer')
            ->setCellValue('B1', 'EINTRAGEN');

// Rename sheet
$objPHPExcel->getActiveSheet(1)->setTitle('Samplel2');

 

Does not work unfortunately.
Unfortunately I found no example where two  sheet are used.

Can you help me?

Greetings from Germany

Coordinator
Nov 2, 2010 at 2:01 PM
$objPHPExcel - new PHPExcel();
// Rename existing worksheet with index 0 (created when creating a new workbook)
$objPHPExcel->getSheet(0)->setTitle('Samplel1');
// Create a new worksheet at index 1
$objPHPExcel->createSheet(1); // Rename sheet $objPHPExcel->getSheet(1)->setTitle('Samplel2');

or

$objPHPExcel - new PHPExcel();
// Rename existing worksheet with index 0 (created when creating a new workbook)
$objPHPExcel->getSheet(0)->setTitle('Samplel1');


// Create a new worksheet
$newSheet = new PHPExcel_Worksheet();
// Rename sheet
$newSheet->setTitle('Samplel2');
// Add new sheet to workbook at index 1
$objPHPExcel->addSheet($newSheet,1); 
Nov 2, 2010 at 2:09 PM

Many Thanks!