Skip to content

Commit

Permalink
Merge pull request #10 from ebanx/feature/subheader-in-csv
Browse files Browse the repository at this point in the history
Fix subheader for CSV
  • Loading branch information
vinivf authored May 25, 2017
2 parents 0fb65a0 + 6f01947 commit 9d05a6d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions xlsxwriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ public function writeSheetHeader($sheet_name, array $header_types, $format = 'xl
return;
}
if ($format == 'csv') {
$this->writeCSVLine($header_types, true, $delimiter);
if (!empty($subheader)) {
$return = '';
$return .= $this->writeCSVLine([' '], NULL, $delimiter);
$return .= $this->writeCSVLine([$subheader], NULL, $delimiter);
$return .= $this->writeCSVLine([' '], NULL, $delimiter);
$return .= $this->writeCSVLine($header_types, true, $delimiter);
return $return;
}
return $this->writeCSVLine($header_types, true, $delimiter);
}
if (!empty($subheader)) {
$this->writeSheetRow($sheet_name, [' '], $format, $delimiter);
Expand Down Expand Up @@ -172,7 +180,7 @@ public function writeSheetRow($sheet_name, array $row, $format = 'xlsx', $delimi
return;
}
if ($format == 'csv') {
$this->writeCSVLine($row, NULL, $delimiter);
return $this->writeCSVLine($row, NULL, $delimiter);
}

self::initializeSheet($sheet_name);
Expand Down Expand Up @@ -220,8 +228,7 @@ protected function finalizeSheet($sheet_name)
$sheet->finalized=true;
}

public function writeCSV(array $data, array $header_types=array(), $delimiter = ';')
{
public function writeCSV(array $data, array $header_types=array(), $delimiter = ';') {
$header_text = array_keys($header_types);

$output = '';
Expand Down

0 comments on commit 9d05a6d

Please sign in to comment.