Search code examples
excelcodeigniterphpexcelexport-to-excel

Export PHPExcel write long number cell - code igniter


While writing the excel file is fine I see that really long numbers are formulas in excel

Example: 3.21E+15

instead of: 3210142008810000

How can I change the format during the PHP Excel Creation?

My code

$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row->member);

and i try code

$object->getActiveSheet()->setCellValueExplicit(0, $excel_row, $row->member, PHPExcel_Cell_DataType::TYPE_STRING);

An uncaught Exception was encountered

Type: PHPExcel_Exception

Message: Invalid cell coordinate 0

Am I missing something?


Solution

  • PHP Excel's setCellValueExplicit requires an alphanumeric coordinate: A1, C27, etc. Basically, you need to give the cell coordinates in one value.

    Since you apparently write on the first column only, try this:

    $coordinate = 'A' . $excel_row;
    
    $object->getActiveSheet()->setCellValueExplicit(
        $coordinate, 
        $row->member,
        PHPExcel_Cell_DataType::TYPE_STRING
    );
    

    Note: PHP Excel is deprecated, you should try PHP Spreadsheet. It's developed by the same vendor and it has a similar API.