/** * Generate a {@link PHPExcel} for the provided DataObject List * @param SS_List $set List of DataObjects * @return PHPExcel */ public function getPhpExcelObject(SS_List $set) { // Get the first object. We'll need it to know what type of objects we // are dealing with $first = $set->first(); // Get the Excel object $excel = $this->setupExcel($first); $sheet = $excel->setActiveSheetIndex(0); // Make sure we have at lease on item. If we don't, we'll be returning // an empty spreadsheet. if ($first) { // Set up the header row $fields = $this->getFieldsForObj($first); $this->headerRow($sheet, $fields); // Add a new row for each DataObject foreach ($set as $item) { $this->addRow($sheet, $item, $fields); } // Freezing the first column and the header row $sheet->freezePane("B2"); // Auto sizing all the columns $col = sizeof($fields); for ($i = 0; $i < $col; $i++) { $sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true); } } return $excel; }