You are here

views_export_xls.module in Views Excel Export 7

Same filename and directory in other branches
  1. 6 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
 */

/**
 * Implements hook_permission().
 */
function views_export_xls_permission() {
  return array(
    'xls export views' => array(
      'title' => t('Export views to xls'),
      'description' => t('Access to export feature of views to xls.'),
    ),
  );
}

/**
 * Implements hook_views_api().
 */
function views_export_xls_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Preprocess xls output template.
 */
function template_preprocess_views_export_xls_view_xls(&$vars) {
  $view = $vars['view'];
  $fields =& $view->field;
  drupal_add_http_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'])) {
        $view->row_index = $num;
        if (isset($field->items) && count($field->items) > 1) {
          $names = explode(', ', strip_tags($field
            ->theme($row)));
          if (count($names) > 1) {
            foreach ($names as $name) {
              $items[$key][] = $name;
            }
          }
          else {
            $items[$key] = strip_tags($names[0]);
          }
        }
        else {
          $items[$key] = strip_tags($field
            ->theme($row));
        }
      }
    }
    $vars['themed_rows'][$num] = $items;
  }
  $vars['file_name'] = $filename;
}

Functions