You are here

protected function Xls::setHeaders in Excel Serialization 8

Set sheet headers.

Parameters

\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet: The worksheet to set headers for.

array $data: The data array.

array $context: The context options array.

1 call to Xls::setHeaders()
Xls::encode in src/Encoder/Xls.php
Encodes data into the given format.

File

src/Encoder/Xls.php, line 167

Class

Xls
Adds XLS encoder support for the Serialization API.

Namespace

Drupal\xls_serialization\Encoder

Code

protected function setHeaders(Worksheet $sheet, array $data, array $context) {

  // Extract headers from the data.
  $headers = $this
    ->extractHeaders($data, $context);
  foreach ($headers as $column => $header) {
    $sheet
      ->setCellValueByColumnAndRow(++$column, 1, $this
      ->formatValue($header));
  }
}