You are here

class ViewsDataExportExporterDOC in Views data export 7.4

This exporter creates a DOC file readable by Microsoft Word. The content is an HTML table, as used by the old XLS export mechanism.

Hierarchy

Expanded class hierarchy of ViewsDataExportExporterDOC

2 string references to 'ViewsDataExportExporterDOC'
DOCExportViewsDataExportExporterTests::getExporterClassName in tests/exporter_tests/doc.test
views_data_export_views_plugins in ./views_data_export.views.inc
Implementation of hook_views_plugins().

File

exporters/views_data_export_exporter_doc.inc, line 9

View source
class ViewsDataExportExporterDOC extends ViewsDataExportExporter {

  /**
   * Regular expression that checks for a valid ISO 8601 date/time.
   */
  const DATE_REGEX_ANY = '/^((\\d{4})(-(\\d{2}))(-(\\d{2})))?(([T \\s]?(\\d{2}))(:(\\d{2}))(:(\\d{2}))?)?$/';
  const DATE_REGEX_DATE = '/^((\\d{4})(-(\\d{2}))(-(\\d{2})))$/';
  const DATE_REGEX_TIME = '/^(([T \\s]?(\\d{2}))(:(\\d{2}))(:(\\d{2}))?)?$/';
  function __construct($options) {
    $this->options = $options;
    parent::__construct($options);
  }

  /**
   * Add a row to our (HTML table) word document.
   *
   * @param $file_handle
   * @param array $data
   * @param int $row_count
   * @param $field_titles
   */
  function add_row(&$file_handle, $data, $row_count, $field_titles) {
    $stripes = array(
      "odd",
      "even",
    );
    $row = $row_count + 1;
    $output = '        <tr class="' . $stripes[$row_count % 2] . '">';
    foreach ($data as $key => $value) {
      $output .= '<td>' . $value . '</td>';
    }
    $output .= '</tr>';
    $output .= PHP_EOL;
    $row++;
    fwrite($file_handle, $output);
  }
  function bof(&$file_handle) {
    $output = '<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  <body>
    <table>
      <thead><tr>';
    foreach ($this->options['field_labels'] as $field) {
      $output .= '<th>' . $field . '</th>';
    }
    $output .= '</tr></thead>
      <tbody>';
    fwrite($file_handle, $output . "\n");
  }
  function eof(&$file_handle, $row_count, $col_count) {
    $output = '      </tbody>
    </table>
  </body>
</html>';
    fwrite($file_handle, $output);
  }
  function post_process(&$results) {
  }
  function get_headers($filename) {
    $headers = parent::get_headers($filename);
    $headers['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
    $headers['Content-Disposition'] = "attachment; filename={$filename}.doc";
    return $headers;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsDataExportExporter::$options public property
ViewsDataExportExporter::clean_xml_tag function
ViewsDataExportExporter::option_definition function Set options fields and default values. Overrides ViewsDataExportExporterInterface::option_definition 3
ViewsDataExportExporter::supports_hide_if_empty function Tell the world whether we support Hide If Empty views option 2
ViewsDataExportExporterDOC::add_row function Add a row to our (HTML table) word document. Overrides ViewsDataExportExporter::add_row
ViewsDataExportExporterDOC::bof function Write the start of the export file. Overrides ViewsDataExportExporter::bof
ViewsDataExportExporterDOC::DATE_REGEX_ANY constant Regular expression that checks for a valid ISO 8601 date/time.
ViewsDataExportExporterDOC::DATE_REGEX_DATE constant
ViewsDataExportExporterDOC::DATE_REGEX_TIME constant
ViewsDataExportExporterDOC::eof function Write the end of the export file. Overrides ViewsDataExportExporter::eof
ViewsDataExportExporterDOC::get_headers function Provide headers to the page when an export file is being downloaded. Overrides ViewsDataExportExporter::get_headers
ViewsDataExportExporterDOC::post_process function Allow final processing of the results. Overrides ViewsDataExportExporter::post_process
ViewsDataExportExporterDOC::__construct function Constructor for views_data_export_exporter classes. Overrides ViewsDataExportExporter::__construct