0

I try to read a spreadsheet however when there is only numbers in a cell, it puts them as .0 digits, ie, if the cell value is 123, it reads it as 123.0 int. Is there a way to read them as raw string?

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

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

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

So output is like

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

and what I want to achieve is

 $arr = ['A', 'B', '123']
senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

0

Could you try something like this:

$valuesSpreadsheet->getActiveSheet()->getStyle('C:C')
    ->getNumberFormat()
    ->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
Peter
  • 1,615
  • 1
  • 9
  • 17
  • I just did `$a = array_map('strval', $a);` and it worked to be honest. I'll update here when I revisit that feature – senty Dec 13 '18 at 00:55