mk-j / PHP_XLSXWriter

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

Strip equal sign when inserting formulas #213

Closed stoppeye closed 1 year ago

stoppeye commented 6 years ago

The equal sign should be stripped when inserting a formula into <f> tags (see Reference).

While Excel will still handle it correctly, it can cause errors in other applications (e.g. Google Sheets).

Adding ltrim on the value can fix this:

} elseif (is_string($value) && $value{0}=='='){
    $file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="s"><f>'.self::xmlspecialchars(ltrim($value, '=')).'</f></c>');
mk-j commented 1 year ago

fixed in https://github.com/mk-j/PHP_XLSXWriter/pull/321