PhpSpreadsheet正在读取时将数字单元格转换为小数

时间:2018-12-13 00:19:35

标签: php excel phpspreadsheet

我尝试读取电子表格,但是当一个单元格中只有数字时,会将其放置为.0位数字,即,如果该单元格值为123,则它将其读取为{{1 }} int。有没有办法将它们读取为原始字符串?

123.0

所以输出就像

  try {
        $inputFileType = IOFactory::identify($path);

        try {
            $reader = IOFactory::createReader($inputFileType);
            $reader->setReadDataOnly(true);
            $valuesSpreadsheet = $reader->load($path);

            try {
                $spreadsheetArr = $valuesSpreadsheet->getActiveSheet()->toArray();
                dd($spreadsheetArr);
            }
        }
  }

我想实现的是

 $arr = ['A', 'B', 123.0]

1 个答案:

答案 0 :(得分:0)

您能尝试这样的事情吗?

$valuesSpreadsheet->getActiveSheet()->getStyle('C:C')
    ->getNumberFormat()
    ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);