mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

When equal sign is the first letter in cell, it is always treated as formula, causing excel reports data in sheet to be corrupted #232

Closed pstepanek1 closed 1 year ago

pstepanek1 commented 5 years ago

It would be great, if string type of the cell is always treated as string, no matter what the content is. The issue I believe is in order of evaluation in writeCell function.

1st is (is_string($value) && $value{0}=='=') ---> set formula later is ($num_format_type=='n_string') ---> set string

Formula type should be examined after the string type (which is supposed to be predefined type). This way string overrides the formula type and excel let you write = sign as the first letter in the cell without any problem being reported.

Magomogo commented 4 years ago

Does anybody know any workarounds for this issue?

@mk-j will you accept the pull request with fix?

mk-j commented 1 year ago

If you can detect that your data starts with "=" just prepend a single quote on it, just like in ex01-multiple-sheets.php