Getting Cell as String in PHPExcel by column and row

前端 未结 2 846
故里飘歌
故里飘歌 2021-01-22 12:07

I am trying to read a cell with possible trailing zeros as a string instead of numeric (which strips off leading zeros). The cell is read by integer column/row as below instead

2条回答
  •  一向
    一向 (楼主)
    2021-01-22 12:18

    $keyCell = $sheet->getCellByColumnAndRow(1,5)->getValue();
    

    Will read the cell data in the format that it's actually stored by Excel, you can't arbitrarily change that or tell PHPExcel to read it as a different datatype.

    However, if the cell has formatting applied, then you can use

    $keyCell = $sheet->getCellByColumnAndRow(1,5)->getFormattedValue();
    

    instead, and this will return the data as a string, with whatever format mask was defined in the Excel spreadsheet

提交回复
热议问题