Answer the question
In order to leave comments, you need to log in
PhpSpreadsheet: How can I format a cell so that it accepts text values without truncating the "+" sign in them?
There is something like this code:
$sheet
->getStyleByColumnAndRow($column, $row)
->getNumberFormat()
->setFormatCode('@')
;
$sheet->setCellValueByColumnAndRow(
$position,
$row,
$value
);
Answer the question
In order to leave comments, you need to log in
Looks like we'll have to fiddle with the DefaultValueBinder heir and assign it to cells.
Look - on the 63rd line of this, the initial "+" is directly cut off, no matter how you deal with cell types.
Faced the same problem - the answer was in the
docs
, maybe it will be useful
to
someone given by code like this
// Set cell A8 with a numeric value, but tell PhpSpreadsheet it should be treated as a string
$spreadsheet->getActiveSheet()->setCellValueExplicit(
'A8', // координаты ячейки
"01513789642", // нужное значение строки
\PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING
);
As an option - to transfer values prefixed with an apostrophe, i.e. instead "+5"
of doing"'+5"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question