When you export a file to CSV and then open it using Microsoft Excel, it defaults to General formatting. This means that phone numbers with a leading zero would be interpreted as a number and the leading zero is dropped. Other things happen like fields get converted to dates, etc. It would be great if it there was an option to force it to be interpreted as Text rather than General. The user could then apply their own formatting within Excel.

The way to do this in the CSV file is to precede the field with an equals sign and then enclose in quotes. Eg ="Name", ="Phone", ="Email"

Any chance we could get the CSV export to include this equals sign before each field?

thanks

Comments

hockey2112’s picture

Rewrite the output of the field. I used the following rewrite code for the customer billing address on an Ubercart website:

="[billing_postal_code]"

StevenWill’s picture

Thanks hockey2112, your suggestion worked for me.

jimconte’s picture

The same technique works for Drupal 8, thanks hockey2112
To get a field to display as text in Twig:

="{{ field_postal_code }}"

ericdsd’s picture

Thanks for the tip,
note that this solution also works for xsl file export.

rewrite any numeric field to ="[your-numeric-field]"

It seems to be an easier fix to this than implementing the hooks that have been added for that purpose on 7.x-3.0 release
https://www.drupal.org/node/2133935

It could eventually be added to the doc.

steven jones’s picture

Status: Active » Closed (won't fix)

Sorry for the lack of attention to your issue, please accept my apologies.

Drupal 7 is going to be end-of-life'd by the community in approximately 1 month.

As such, I am closing all non-critical looking, non-PHP compatibility issues for Views Data Export to tidy up the issue queues and reduce the noise. You can read about this on #3492246: Close down Drupal 7 issues.

If you feel like this issue has been closed by mistake, please do comment about re-opening it.
If you feel like the ticket is still relevant for the 8.x-1.x version of the module, then please search for a duplicate issue first, and if there really isn't one (and you've looked properly) then change the version on the ticket and re-open.

Thanks to everyone involved in this issue: for reporting it, and moving it along, it is truly appreciated.
The Drupal community wouldn't be what it is today without your involvement and effort, so I'm sorry that we couldn't get this issue resolved. Hopefully we'll work together in a future issue though, and get that one resolved :)