Last active
August 29, 2015 14:10
-
-
Save iansltx/0b3244c3b055c398a02b to your computer and use it in GitHub Desktop.
PHPExcel Convenience Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // use as-is with PHPExcel, or build a utility class around them | |
// $addColumn($sheet, 'A', 1, ['value_in_A1', 'value_in_A2']); | |
$addColumn = function(\PHPExcel_Worksheet $worksheet, $column, $row, $values) { | |
for ($i = 0, $count = count($values); $i < $count; $i++, $row++) | |
$worksheet->getCell($column . $row)->setValue($values[$i]); | |
}; | |
// $addRow($sheet, 'A', 1, ['value_in_A1', 'value_in_B1']); | |
$addRow = function(\PHPExcel_Worksheet $worksheet, $column, $row, $values) { | |
for ($i = 0, $count = count($values); $i < $count; $i++, $column++) | |
$worksheet->getCell($column . $row)->setValue($values[$i]); | |
}; | |
// $addMatrix($sheet, 'A', 1, [['value_in_A1', 'value_in_B1'], ['value_in_A2', 'value_in_B2']]); | |
$addMatrix = function(\PHPExcel_Worksheet $worksheet, $column, $row, $values) use ($addRow) { | |
for ($i = 0, $count = count($values); $i < $count; $i++, $row++) | |
$addRow($worksheet, $column, $row, $values[$i]); | |
}; | |
// $setWidths($sheet, [10, 15, 20, 15], 'B'); | |
$setWidths = function(\PHPExcel_Worksheet $worksheet, $values, $left_column = 'A') { | |
for ($i = 0, $count = count($values); $i < $count; $i++, $left_column++) | |
$worksheet->getColumnDimension($left_column)->setWidth($values[$i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blog post on inspiration here: http://empoweringaccess.tumblr.com/post/103189682800/phpexcel-functional-programming