1 |
a45e4bc1
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* The Excel exporter currently is just a tab-delimited export.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
class webform_exporter_excel_delimited extends webform_exporter_delimited {
|
9 |
|
|
function __construct($options) {
|
10 |
|
|
$options['delimiter'] = '\t';
|
11 |
|
|
parent::__construct($options);
|
12 |
|
|
}
|
13 |
|
|
|
14 |
|
|
function bof(&$file_handle) {
|
15 |
|
|
$output = '';
|
16 |
|
|
|
17 |
|
|
// Include at BOM at the beginning of the file for Little Endian.
|
18 |
|
|
// This makes tab-separated imports work correctly in MS Excel.
|
19 |
|
|
if (function_exists('mb_convert_encoding')) {
|
20 |
|
|
$output = chr(255) . chr(254);
|
21 |
|
|
}
|
22 |
|
|
@fwrite($file_handle, $output);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
function add_row(&$file_handle, $data, $row_count) {
|
26 |
|
|
foreach ($data as $key => $value) {
|
27 |
|
|
// Escape inner quotes and wrap all contents in new quotes.
|
28 |
|
|
$data[$key] = '"' . str_replace('"', '""', $data[$key]) . '"';
|
29 |
|
|
|
30 |
|
|
// Remove <script> tags, which mysteriously cause Excel not to import.
|
31 |
|
|
$data[$key] = preg_replace('!<(/?script.*?)>!', '[$1]', $data[$key]);
|
32 |
|
|
}
|
33 |
|
|
$row = implode($this->delimiter, $data) . "\n";
|
34 |
|
|
|
35 |
|
|
if (function_exists('mb_convert_encoding')) {
|
36 |
|
|
$row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
@fwrite($file_handle, $row);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
function set_headers($filename) {
|
43 |
|
|
drupal_add_http_header('Content-Type', 'application/x-msexcel');
|
44 |
|
|
drupal_add_http_header('Content-Disposition', "attachment; filename=$filename.xls");
|
45 |
|
|
drupal_add_http_header('Pragma', 'public');
|
46 |
|
|
drupal_add_http_header('Cache-Control', 'max-age=0');
|
47 |
|
|
}
|
48 |
|
|
} |