mirror of
https://github.com/SuiteCRM/SuiteCRM.git
synced 2026-03-02 19:16:58 -05:00
[PATCH] Bad CSV export on Reports module #9
Labels
No labels
Area: API
Area: Campaigns
Area: Cases
Area: Clean Up
Area: Clean Up: Performance
Area: Dashlets
Area: Databases
Area: Developer Tools
Area: Elasticsearch
Area: Elasticsearch
Area: Emails
Area: Emails:Campaigns
Area: Emails:Cases
Area: Emails:Compose
Area: Emails:Config
Area: Emails:Templates
Area: Environment
Area: Installation
Area: Language
Area: Mobile
Area: Module
Area: PDFs
Area: PHP8
Area: Reports
Area: Studio
Area: Styling
Area: Upgrading
Area: Workflow
Area:Activity Stream
Area:Calls
Area:Import
Area:Projects
Area:Search
Area:Surveys
Area:Themes
Area:Users
Branch:Hotfix
Good First Issue
Hacktoberfest
Help Wanted
PR:Community Contribution
PR:Type:Enhancement
Priority:Critical
Priority:Important
Priority:Moderate
Severity: Major
Severity: Minor
Severity: Moderate
Status: Requires Code Review
Status: Requires Updates
Status: Stale
Status: Team Investigating
Status:Assessed
Status:Fix Proposed
Status:Needs Assessed
Status:Requires Automated Tests
Type: Bug
Type:Deprecated
Type:Discussion
Type:Duplicate
Type:Invalid
Type:Question
Type:Suggestion
Type:Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/SuiteCRM-SuiteCRM#9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lsmonki on GitHub (Mar 6, 2014).
Originally assigned to: @mattlorimer on GitHub.
The csv export do not escapes quotes ("), do not support new lines on field content, and can't be oppened without problems on excel. Also the http headers do not set the filename ok.
Here is a patch for the
build_report_csvfunction onmodules/AOR_Reports/AOR_Report.php@ghost commented on GitHub (May 19, 2014):
Thank you for this patch! It worked flawlessly to fix my issue with fields "shifting" on my CSV exports.
@iYianni commented on GitHub (Jul 2, 2015):
Is this included in the latest release of SuiteCRM?
@darthtang commented on GitHub (Jul 30, 2015):
Sorry. This patch hasnt been added ye,
However, i have replaced the old function with this new patch function and it still doesn't seem to work.
I am using a new version of suite 7.2.2, and considering this patch was long ago, maybe something has broken in the process of a new version being used
@iYianni , have you also tried to replace the old function with the new function?
@iYianni commented on GitHub (Jul 30, 2015):
@darthtang Yes, I replaced the code from version 7.1.2 and it works fine. Having looked at the code in the latest release, an attempt has been made to resolve the issues. Though, I haven't actually tested it.
What issues are you experiencing?
@darthtang commented on GitHub (Jul 30, 2015):
Hi @iYianni
So the latest release has the new change? i am looking at the master branch now of suite and cannot see the change.
The issues i am experiencing are that the quotes are still not escaped i get """ in the csv file when i export my report
@iYianni commented on GitHub (Jul 30, 2015):
It's not the same code as above, but the latest release looks like it is attempting to deal with (at least some of) these issues. As we're not using it yet, and without testing it, I won't be able to tell for sure, sorry. Have you check with @willrennie or @lsmonki for help with the latest release?
@darthtang commented on GitHub (Jul 30, 2015):
@lsmonki
What were the errors before you added the changes into Suite? I know it was a long time ago when you posted this so no worries if you cant remember!
Cheers
Darren
@lsmonki commented on GitHub (Jul 30, 2015):
Some problems are described here: http://stackoverflow.com/questions/1241220/generating-csv-file-for-excel-how-to-have-a-newline-inside-a-value
First, you need to add the BOM to allow excell open it and get new lines on fields:
NOTE: The code was copied from SugarCRM, the bug numbers are from their issues list.
Now there is a problem, the last field names and values for each row has an end delimiter and it shouldn't (do it on field names and field values):
Now you need to scape quotes and fix new lines, in the new code you can modify the encloseForCSV function
And in the new code I see an error, if you are going to modify the csv content, modify it before setting the headers, the length could change:
NOTE: I have not tested it :)
@lsmonki commented on GitHub (Jul 30, 2015):
Other error, the double equal sign must be a single equal:
@samus-aran commented on GitHub (Apr 1, 2017):
Ok @lsmonki Revisiting the past.
Looking at the now 7.8.x code I can see the following points.
Content adjusted before length header set:
This has been resolved in the later versions.
https://github.com/salesagility/SuiteCRM/blob/master/export.php#L92
Double equal sign must be a single equal: https://github.com/salesagility/SuiteCRM/issues/18#issuecomment-126304976
Not quite sure what this is referring to as it has always been a single equal sign.
https://github.com/salesagility/SuiteCRM/blob/master/export.php#L92
The delimiter at the end of each column has been raised as a separate bug:
https://github.com/salesagility/SuiteCRM/issues/3275
Seems the only remaining bit is that the build_report_csv does not contain the $BOM reference though calling the export_utils.php
I would deem this as a bug as if it already contains this on the export of other CSV it really should in Reports.
@ghost commented on GitHub (Apr 27, 2017):
Guys, I know you are working hard, but a three (* yes, 3! *) years old BUG/issue should have been taken care of by now... I am expriencing the same problem for years and my users complained again about this today...
we know that themes are important but not as important as normal functionalities to my opinion...
@Mac-Rae commented on GitHub (Jul 26, 2019):
Confirmed in latest 7.10.x
@gunnicom commented on GitHub (Sep 27, 2019):
Still issues with double quotes " in csv exports on 7.11.7
@pgorod commented on GitHub (Sep 27, 2019):
Maybe this PR will help for this Issue here?
#7580
I'm not sure it does, though, I didn't examine the code, it just looks related...
@gunnicom commented on GitHub (Sep 30, 2019):
@pgorod That seems to be encoding related.
Double quotes is definitly a different thing, as they need to be escaped somehow.
@carlos-cumplisoft commented on GitHub (May 14, 2025):
I also have encountered problems using export on windows systems and trying to open csv in excel, but in my solution (SuiteCRM 7.11.18), I have to do only small changes. I think maybe, in combination with @lsmonki solution, we could get a better solution.
The problem as far as I know is not only on printCSV on include/export_utils.php, we also have to make changes to file include/Localization/Localization.php.
I added a new charset to $availableCharsets array, 'Windows-1251', this give me the chance of could set on any user profile this charset on exporting, and also could be the default by configuration (for those who use windows).
So the new code on Localization array should be:
and also iconvCharsetMap array shoud be:
In my case I only have to make an slightly modification to call Localization->translateCharset on file include/export_utils.php change function printCSV:
Change the line
for this one:
Note that, I didn't need to force excel compatibility (This is an option on config.php file).
In my case I need a language charset on windows that use Windows1252, but other people could be need other one.
Also note, if you look inside translateCharset function, the function mb_list_encodings, give the list of system available character codes, so with this, I think you need only to know if you have Windows1252 on this list on your system and add it to availableCharsets, with this you will don't need to change printCSV, and maybe the best solution should be to load available charsets on configuration / user profile, instead of using a hardcoded one, because in my system the harcoded array one is only a small subset of available ones. Also, I think that if you chose a harcoded one that really isn't in your system, it will fail.
@carlos-cumplisoft commented on GitHub (May 14, 2025):
I tested my last words on my comment, and this is an alternative solution that also works.
With this solution you only have to add a line in include/Localization/Localization.php file. change the constructor from:
to
And after this change, you only have to select, in my case, windows-1252 character set. The csv generated will be opened without problems on windows with double click.
May be also we can merge harcoded array with system one but I think is better take it from system.
I hope this will help!