How to get exact value from cell

Topics: Developer Forum
Sep 12, 2013 at 9:13 PM
Hi,

I'm wondering on how to get the exact value form cells, for example I got 4 columns;
  1. Deposit
  2. 450.00
  3. 3
  4. 1350.00
When I try to get the data using
$objWorksheet->getCellByColumnAndRow($col, $row)->getValue()
the Integer will become Float, and the floating point disappeared.
 [0]=>
  array(1) {
    ["columns"]=>
    array(4) {
      [0]=>
      array(2) {
        ["index"]=>
        string(1) "A"
        ["value"]=>
        string(7) "Deposit"
      }
      [1]=>
      array(2) {
        ["index"]=>
        string(1) "B"
        ["value"]=>
        float(450)
      }
      [2]=>
      array(2) {
        ["index"]=>
        string(1) "C"
        ["value"]=>
        float(3)
      }
      [3]=>
      array(2) {
        ["index"]=>
        string(1) "D"
        ["value"]=>
        float(1350)
      }
    }
  }
How to get the exact data type from the cells? Or is there any way I can format the cell value so I can get the numbers exactly like in source file.

Thank you.
Coordinator
Sep 12, 2013 at 9:40 PM
Edited Sep 12, 2013 at 9:42 PM
You are getting back the actual value from the cells.

Whenever you look at a cell in MS Excel, you are seeing the value with a formatting mask applied, so if you see 1350.00 you are looking at a float value of 1350 with a format mask applied telling MS Excel to display it with 2 decimal places (something like #0.00")

If you want to see the formatted value, then you can use any of the standard PHP number formatting options (e.g. sprint() or number_format()) to format it however you want. If you want PHPExcel to return the formatted value, then use
$objWorksheet->getCellByColumnAndRow($col, $row)->getFormattedValue();
Sep 13, 2013 at 2:02 AM
thank you very much.