You are here

protected function Xls::setData in Excel Serialization 8

Set sheet data.

Parameters

\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet: The worksheet to put the data in.

array $data: The data to be put in the worksheet.

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

File

src/Encoder/Xls.php, line 258

Class

Xls
Adds XLS encoder support for the Serialization API.

Namespace

Drupal\xls_serialization\Encoder

Code

protected function setData(Worksheet $sheet, array $data) {
  foreach ($data as $i => $row) {
    $column = 1;
    foreach ($row as $value) {

      // Since headers have been added, rows are offset here by 2.
      $sheet
        ->setCellValueByColumnAndRow($column, $i + 2, $this
        ->formatValue($value));
      $column++;
    }
  }
}