phpexcel set data type on range of cells

前端 未结 1 2003
粉色の甜心
粉色の甜心 2021-02-05 06:50

With PHPExcel, I\'m using:

$workSheet->fromArray($array);

To set my data. However, one column needs to be set as string (a number with a leading

相关标签:
1条回答
  • 2021-02-05 07:37

    There is currently no method in PHPExcel that will allow you to set the data type for a range of cells, only for an individual cell.

    There are a couple of options... the harder would be to write a custom Cell Value Binder that automatically sets the data type for those cells to string when the cell value is set by fromArray().

    What you could do instead (and is far easier), is to leave the datatype as a number, and the value as a numeric, but to set a number format mask which tells Excel to display the numbers with leading zeroes.

    $objPHPExcel->getActiveSheet()->getStyle('L3:N2048')
                                  ->getNumberFormat()->setFormatCode('0000');
    
    0 讨论(0)
提交回复
热议问题