Skip to content

Commit

Permalink
Merge pull request #9 from ebanx/feature/print-subheader
Browse files Browse the repository at this point in the history
Print subhead in reports
  • Loading branch information
vinivf authored May 25, 2017
2 parents 0c37308 + 9813e05 commit 0fb65a0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions xlsxwriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,30 @@ protected function initializeSheet($sheet_name)
$sheet->file_writer->write( '<sheetData>');
}

public function writeSheetHeader($sheet_name, array $header_types, $format = 'xlsx', $delimiter = ';') {
public function writeSheetHeader($sheet_name, array $header_types, $format = 'xlsx', $delimiter = ';', $subheader = NULL) {
if (empty($sheet_name) || empty($header_types) || !empty($this->sheets[$sheet_name])) {
return;
}
if ($format == 'csv') {
$this->writeCSVLine($header_types, true, $delimiter);
}
if (!empty($subheader)) {
$this->writeSheetRow($sheet_name, [' '], $format, $delimiter);
$this->writeSheetRow($sheet_name, [$subheader], $format, $delimiter);
$this->writeSheetRow($sheet_name, [' '], $format, $delimiter);
$start = 3;
} else {
$start = 0;
}

self::initializeSheet($sheet_name);
$sheet = &$this->sheets[$sheet_name];
$sheet->cell_formats = array_values($header_types);
$header_row = array_keys($header_types);

$sheet->file_writer->write('<row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="12.1" outlineLevel="0" r="' . (1) . '">');
$sheet->file_writer->write('<row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="12.1" outlineLevel="0" r="' . ($start + 1) . '">');
foreach ($header_row as $k => $v) {
$this->writeCell($sheet->file_writer, 0, $k, $v, 'blackheader');
$this->writeCell($sheet->file_writer, $start, $k, $v, 'blackheader');
}
$sheet->file_writer->write('</row>');
$sheet->row_count++;
Expand Down

0 comments on commit 0fb65a0

Please sign in to comment.