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" :) **
Comments
Comment #1
danielb commentedhttp://drupal.org/node/334507