Thursday, March 28, 2013

Re: Writing data into a new worksheet using PHPExcel in Cakephp

Hello,

I don't know about your addTable*() functions, my guess is when you do a addSheet() you shoud either store the returned value as currentSheet or use $this->xls->setActiveSheetIndex()

Cheers,
RĂ©mi

On Wednesday, 27 March 2013 16:29:58 UTC+1, Victor Musvibe wrote:
I am using PHPExcel to generate reports for my application in cakephp.  The first worksheet is perfectly done but when I want to write on the same workbook different new worksheet, phpexcel just creates the worksheet but does not post data. For example record with id = 1 shows on its worksheet and id =2 shows on its worksheet...etc

Here is my code for my addsheet that inserts a new tab

    /**
    * Create new worksheet
    */
    public function createWorksheet() {
    $this->loadEssentials();
    $this->xls = new PHPExcel();
    }

    public function addSheet($tab) {
    $newWorksheet = new PHPExcel_Worksheet($this->xls, $tab);
    $this->xls->addSheet($newWorksheet);
    }
   
    //other code
   
    and here is my view for the worksheet

    <?php
    $this->PhpExcel->createWorksheet();
    $this->PhpExcel->setDefaultFont('Calibri', 12);

    // define table cells
    $table = array(
    array('label' => __('id'), 'width' => 'auto', 'filter' => true),
    array('label' => __('name'), 'width' => 'auto', 'filter' => true),
    array('label' => __('type'), 'width' => 'auto', 'filter' => true),
    array('label' => __('comment'), 'width' => 'auto', 'filter' => true),
    array('label' => __('status type'), 'width' => 'auto', 'filter' => true),
    array('label' => __('created'), 'width' => 'auto', 'filter' => true),
    );

    // heading
    $this->PhpExcel->addTableHeader($table, array('name' => 'Cambria', 'bold' => true));

    foreach ($itQueries as $d) {
    $this->PhpExcel->addSheet($d['ItQuery']['id']);
    $this->PhpExcel->addTableRow(array(
    $d['ItQuery']['id'],
    $d['ItQuery']['hr_employee_id'],
    $d['ItQuery']['it_query_type_id'],
    $d['ItQuery']['comment'],
    $d['ItQuery']['status_type'],
    $d['ItQuery']['created'],
    ));
    }

    $this->PhpExcel->addTableFooter();
    $this->PhpExcel->output();
    $this->PhpExcel->exit();
    ?>
   
Its my first time using the helper

I have posted this question on OS as well, hoping to get a quick response on this group - http://stackoverflow.com/questions/15501509/writing-data-into-a-new-worksheet-using-phpexcel-in-cakephp 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: