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

webchick’s picture

Status: Active » Needs review
StatusFileSize
new2.16 KB

I implemented this slightly differently, but thanks for the push in the right direction. We should fix the 'seperator' misspelling in another patch.

webchick’s picture

Oops. Helps to spell default_value right. ;) Ironic! ;)

neclimdul’s picture

Status: Needs review » Fixed

Committed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.