Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When exporting to an Excel spreadsheet, formatted text in some Drupal fields results in split cells - so a single record in Drupal may be broken onto multiple rows in Excel, where data for some fields is broken onto multiple rows, and data for each of the remaining fields is placed in a single merged cell spanning all the rows for that record (see column M in the attached screenshot)
Comment | File | Size | Author |
---|---|---|---|
#1 | screenshot.jpg | 132.37 KB | nickap |
Comments
Comment #1
nickap CreditAttribution: nickap commentedComment #1.0
nickap CreditAttribution: nickap commentedembedded image did not display
Comment #2
jp.stacey CreditAttribution: jp.stacey commentedThis still seems to be a bug - or maybe it's a feature, in which case can it be switched off?
Right now we're exporting as XLS rather than CSV, because CSV doesn't seem to preserve Unicode reliably (accented characters in Spanish names); however, a single row is actually many merged rows, simply because there are newlines in the body field.
Is this even a desirable default? Can it be overridden just in time using a theme function?
Comment #3
jp.stacey CreditAttribution: jp.stacey commentedFor reference, here's a few workarounds that eventually seem to lead to having all your text in a single cell, not split over lines:
* Formatter: plain text
* Style settings: remove any customized HTML, field templates etc. as otherwise they "trap" leading and trailing whitespace
* Rewrite results: remove whitespace; and convert newlines to
tags. Otherwise the plain-text newlines get treated as simple spaces.
Comment #4
liquidcms CreditAttribution: liquidcms as a volunteer commentedModifying this thread a little to cover other cases of field content (not just body) causing multiple rows in XLS format.
I use Address field which spits out a full address as a single field. In HTML this has DIVs as wrappers around each line of the address.
CSV format strips all html (by default) and leaves everything as one long line with no separators. Leaving HTML in of ocurse leaves all the DIV tags in which is also no good.
XLS has no options and does what is reported here and seems to break each DIV into its own row (which i doubt would ever be correct).
Comment #5
liquidcms CreditAttribution: liquidcms as a volunteer commentedComment #6
liquidcms CreditAttribution: liquidcms as a volunteer commentedi have managed to fix my issue (with address fields) using this: #1493014: Add line breaks in the rendered address markup to improve address field data exports and possibly helped along with the VDE addon module for using PHPExcel.
Comment #7
pvanerk CreditAttribution: pvanerk commentedYou can overwrite the theme file for the export. Replace de
and
by tags which are recognized by Excel.
Go to to the module on your filesystem "modules/views_data_export/theme".
Edit "views-data-export-xls-body.tpl.php".
Of course you shouldn't put this statement in the "modules/views_data_export/theme/views-data-export-xls-body.tpl.php" but place it in a custom overwrite theme file otherwise your changes are lost when upgrading the views_data_export module.
Comment #8
ArtusamakYou can solve this problem with the following solution to add in your theme to remove the HTML from the outputted fields (that will not be interpreted by Excel). You can keep line breaks with the last line of the snippet: