Skip to content

Fixes automatically hidden columns for some versions of Excel readers #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2018-06-0.38
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions xlsxwriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function writeToFile($filename)
$zip->close();
}

protected function initializeSheet($sheet_name, $col_widths=array() )
protected function initializeSheet($sheet_name, $num_cols=0, $col_widths=array() )
{
//if already initialized
if ($this->current_sheet==$sheet_name || isset($this->sheets[$sheet_name]))
Expand Down Expand Up @@ -149,8 +149,15 @@ protected function initializeSheet($sheet_name, $col_widths=array() )
$sheet->file_writer->write( '<col collapsed="false" hidden="false" max="'.($i+1).'" min="'.($i+1).'" style="0" width="'.floatval($column_width).'"/>');
$i++;
}
} else if ($num_cols > 0) {
for ($i=0; $i<$num_cols; $i++) {
$sheet->file_writer->write( '<col collapsed="false" hidden="false" max="'.($i+1).'" min="'.($i+1).'" style="0" width="11.5"/>');
}
} else {
// Some excel readers might not parse this and automatically
// hide all columns up to 1024 (AMK column)
$sheet->file_writer->write( '<col collapsed="false" hidden="false" max="1024" min="'.($i+1).'" style="0" width="11.5"/>');
}
$sheet->file_writer->write( '<col collapsed="false" hidden="false" max="1024" min="'.($i+1).'" style="0" width="11.5"/>');
$sheet->file_writer->write( '</cols>');
$sheet->file_writer->write( '<sheetData>');
}
Expand Down Expand Up @@ -193,7 +200,7 @@ public function writeSheetHeader($sheet_name, array $header_types, $col_options
$style = &$col_options;

$col_widths = isset($col_options['widths']) ? (array)$col_options['widths'] : array();
self::initializeSheet($sheet_name, $col_widths);
self::initializeSheet($sheet_name, count($header_types), $col_widths);
$sheet = &$this->sheets[$sheet_name];
$sheet->columns = $this->initializeColumnTypes($header_types);
if (!$suppress_row)
Expand Down