Wednesday, 20 November 2019

PhpSpreadsheet - how to determine if a number is formatted as text?

I have a simple spreadsheet with a number formatted as text:

LibreOffice screenshot

I want to use PhpSpreadsheet to determine that the number is indeed formatted as text instead of the default "General". So I do this:

<?php

use PhpOffice\PhpSpreadsheet\IOFactory;

require 'vendor/autoload.php';

$reader = IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);

$cell = $reader->load('index.xlsx')->getActiveSheet()->getCell('A1');
var_dump($cell->getValue(), $cell->getStyle()->getNumberFormat()->getFormatCode());

But the result is always this:

float(12345)
string(7) "General"

How to determine if the number is formatted as "Text"?



from PhpSpreadsheet - how to determine if a number is formatted as text?

No comments:

Post a Comment