You are here

views_export_xls.module in Views Excel Export 6

Same filename and directory in other branches
  1. 7 views_export_xls.module

Gives the ability to export to excel

File

views_export_xls.module
View source
<?php

/**
 * @file
 * Gives the ability to export to excel
 */

/**
 * Implementation of hook_perm().
 */
function views_export_xls_perm() {
  return array(
    'xls export views',
  );
}

/**
 * Implementation of hook_views_api().
 */
function views_export_xls_views_api() {
  return array(
    'api' => 2,
  );
}

/**
 * Preprocess xls output template.
 */
function template_preprocess_views_export_xls_view_xls(&$vars) {
  $view = $vars['view'];
  $fields =& $view->field;
  drupal_set_header('Cache-Control: max-age=60, must-revalidate');
  $filename = strtr($vars['options']['filename'], array(
    '%view' => check_plain($view->name),
  ));
  $rows = $vars['rows'];
  $vars['header'] = array();
  foreach ($fields as $key => $field) {
    if (empty($field->options['exclude'])) {
      $vars['header'][$key] = check_plain($field
        ->label());
    }
  }
  $vars['themed_rows'] = array();
  foreach ($rows as $num => $row) {
    $items = array();
    foreach ($fields as $key => $field) {
      if (empty($field->options['exclude'])) {
        $items[$key] = strip_tags($view->style_plugin->rendered_fields[$num][$key]);
      }
    }
    $vars['themed_rows'][$num] = $items;
  }
  $vars['file_name'] = $filename;
}

Functions

Namesort descending Description
template_preprocess_views_export_xls_view_xls Preprocess xls output template.
views_export_xls_perm Implementation of hook_perm().
views_export_xls_views_api Implementation of hook_views_api().