You are here

public function webform_exporter_excel_delimited::add_row in Webform 7.4

Add a single row to the export file.

Parameters

$file_handle: A PHP file handle to the export file.

array $data: An array of formatted data for this row. One cell per item.

int $row_count: The current number of rows in the export file.

Overrides webform_exporter_delimited::add_row

File

includes/exporters/webform_exporter_excel_delimited.inc, line 33

Class

webform_exporter_excel_delimited
The Excel exporter currently is just a tab-delimited export.

Code

public function add_row(&$file_handle, array $data, $row_count) {
  foreach ($data as $key => $value) {

    // Escape inner quotes and wrap all contents in new quotes.
    $data[$key] = '"' . str_replace('"', '""', $data[$key]) . '"';

    // Remove <script> tags, which mysteriously cause Excel not to import.
    $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);
}