webform_exporter_excel_delimited.inc in Webform 7.4
File
includes/exporters/webform_exporter_excel_delimited.inc
View source
<?php
class webform_exporter_excel_delimited extends webform_exporter_delimited {
public function __construct($options) {
$options['delimiter'] = '\\t';
parent::__construct($options);
}
public function bof(&$file_handle) {
$output = '';
if (function_exists('mb_convert_encoding')) {
$output = chr(255) . chr(254);
}
@fwrite($file_handle, $output);
}
public function add_row(&$file_handle, array $data, $row_count) {
foreach ($data as $key => $value) {
$data[$key] = '"' . str_replace('"', '""', $data[$key]) . '"';
$data[$key] = preg_replace('!<(/?script.*?)>!', '[$1]', $data[$key]);
}
$row = implode($this->delimiter, $data) . "\n";
if (function_exists('mb_convert_encoding')) {
$row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
}
@fwrite($file_handle, $row);
}
public function set_headers($filename) {
drupal_add_http_header('Content-Type', 'application/x-msexcel');
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $this
->get_filename($filename));
drupal_add_http_header('Pragma', 'public');
drupal_add_http_header('Cache-Control', 'max-age=0');
}
public function get_filename($filename) {
return $filename . '.xls';
}
}