grido icon indicating copy to clipboard operation
grido copied to clipboard

CSV export: cse fputcsv instead of custom $escape and $print

Open lucien144 opened this issue 8 years ago • 3 comments

How about using fputcsv instead of custom escaping and custom print?

        $print = function(array $row) {
            $out = fopen('php://output', 'w');
            fputcsv($out, $row, ";");
            fclose($out);
        };

lucien144 avatar Apr 26 '16 08:04 lucien144

Can you explain your troubles with Export?

o5 avatar Apr 26 '16 09:04 o5

When I was exporting ~25MB CSV, the CSV was malformatted and could not be opened. Another issue was that $escape wraps empty cells to "" which eg. Numbers on OS X displays as a column with "".

When I created my own Export with fputcsv all worked.

In other words, PHP's fputcsv seems to do a better job that your custom $escape and $print, it also seems to be faster and the code is smaller.

It's just a suggestion :)

lucien144 avatar Apr 26 '16 12:04 lucien144

I already used fputcsv() in export. I don't remember why this method is not used, but referenced commit resolved marked issues (from commit msg).

I'll really appreciate pull request with your changes in export class and also in test-cases (there should be test data which does not work with current export)

o5 avatar Apr 26 '16 14:04 o5