It would be useful to have an option to show a row with labels for each of the fields as defined in the view. Right now, the CSV export only exports the data rows but does not include a header row.
For example:
First NameLast NameFavorite Color
JohnDoeBlue
SallyJacobsRed
I modified my own code locally to make this happen and it was a very easy fix:
(The business of headerCount is a workaround related to another bug I filed about add'l columns being output that aren't defined in the view. I had to do this to keep the headers lined up with the data that is being output)
In views_bonus_plugin_style_export_csv.inc
------------------------------------------------------------------
Add support for a new checkbox option named "showHeaders"
In views-bonus-export-csv.tpl.php:
------------------------------------------------------------------
if ($options['showHeaders']) {
if ($options['quote']) echo '"';
echo "Node ID";
$headerCount = 1;
foreach($header as $label) {
if ($headerCount == count($header)) {
echo $seperator . "?";
}
echo $seperator . $label;
$headerCount++;
}
if ($options['quote']) echo '"';
echo "\r\n";
}
** RELATED BUG: The "seperator" variable is misspelled -- it should be "separator" :) **
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views-bonus-export-csv-header-row-334507-2.patch | 2.14 KB | webchick |
| #1 | views-bonus-export-csv-header-row-334507-1.patch | 2.16 KB | webchick |
Comments
Comment #1
webchickI implemented this slightly differently, but thanks for the push in the right direction. We should fix the 'seperator' misspelling in another patch.
Comment #2
webchickOops. Helps to spell default_value right. ;) Ironic! ;)
Comment #3
neclimdulCommitted