rap2hpoutre / fast-excel

🦉 Fast Excel import/export for Laravel
MIT License
2.08k stars 246 forks source link

Excel File Treats Cell Content Starting with +,-,=,@ as Formula #356

Open LauKL1991 opened 4 months ago

LauKL1991 commented 4 months ago

Hi,

I have encountered an issue while using FastExcel for exporting data to Excel files. It seems that when a cell's content starts with certain characters such as +, -, =, @, Excel treats it as a formula rather than string.

This behavior causes unexpected results in the exported Excel file, especially when the content is intended to be interpreted as text rather than a formula. For example, if the cell content is "-12345" or "=ABC", Excel interprets it as a formula rather than a simple text entry.

I believe this behavior is not ideal, as it can lead to data misinterpretation and inconsistencies, particularly in scenarios where the leading characters are part of the data itself and not intended to be treated as formulas. Also, this would crash the Excel file when trying to open the file after export

I kindly request your assistance in addressing this issue. It would be greatly appreciated if FastExcel could provide an option or workaround to ensure that Excel treats cell content starting with +, -, =, @ as strings rather than formulas.

Thank you.

ariprw commented 1 month ago

Let's do a little manipulation to find the first character, namely @, we can add the symbol '.

I also tested it when exporting from database in Laravel on create_at column, the resulting data is not correct.

The way to overcome this is to use

use Carbon\Carbon;

Carbon::parse($data->created_at)->translatedFormat('Y-m-d H:i:s')

I tried exporting 3 columns, 200,000 rows, it ran smoothly with a duration of 35s