Skip to content

Commit

Permalink
ExcelWriter: Optimize code at writeItem()
Browse files Browse the repository at this point in the history
Fix typo at ExcelWriterTest.php
  • Loading branch information
igormukhingmailcom authored and ddeboer committed May 30, 2015
1 parent c3230b1 commit 2870f94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/Writer/ExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ public function prepare()
*/
public function writeItem(array $item)
{
$count = count($item);

if ($this->prependHeaderRow && 1 == $this->row) {
$headers = array_keys($item);
$count = count($headers);
$values = array_values($headers);

for ($i = 0; $i < $count; $i++) {
$this->excel->getActiveSheet()->setCellValueByColumnAndRow($i, $this->row, $values[$i]);
$this->excel->getActiveSheet()->setCellValueByColumnAndRow($i, $this->row, $headers[$i]);
}
$this->row++;
}

$count = count($item);
$values = array_values($item);

for ($i = 0; $i < $count; $i++) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Writer/ExcelWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testHeaderNotPrependedByDefault()
->finish();

$excel = \PHPExcel_IOFactory::load($file);
$sheet = $this->worksheet = $excel->getActiveSheet()->toArray();
$sheet = $excel->getActiveSheet()->toArray();

# Values should be at first line
$this->assertEquals(array('col 1 value', 'col 2 value', 'col 3 value'), $sheet[0]);
Expand Down Expand Up @@ -119,7 +119,7 @@ public function testHeaderPrependedWhenOptionSetToTrue()
->finish();

$excel = \PHPExcel_IOFactory::load($file);
$sheet = $this->worksheet = $excel->getActiveSheet()->toArray();
$sheet = $excel->getActiveSheet()->toArray();

# Check column names at first line
$this->assertEquals(array('col 1 name', 'col 2 name', 'col 3 name'), $sheet[0]);
Expand Down

0 comments on commit 2870f94

Please sign in to comment.