Correct format for strings / numbers beginning with zero?

后端 未结 6 1542
梦谈多话
梦谈多话 2020-12-03 01:31

I\'m trying to use PHP to create a file containing a list of phone numbers. It\'s working OK however if the phone number begins with zero, the digit is dropped from the Exce

6条回答
  •  执笔经年
    2020-12-03 01:36

    Either:

    // Set the value explicitly as a string
    $objPHPExcel->getActiveSheet()->setCellValueExplicit('A1', '0029', PHPExcel_Cell_DataType::TYPE_STRING);
    

    or

    // Set the value as a number formatted with leading zeroes
    $objPHPExcel->getActiveSheet()->setCellValue('A3', 29);
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getNumberFormat()->setFormatCode('0000');
    

提交回复
热议问题