/** * Extend standard worksheet by fixing width of last column (errors) * * @param string $title Name of worksheet * @param array $data Data to Export * * @return object PHPExcel_Worksheet */ function createWorksheet($title, $data) { $xlWS = parent::createWorksheet($title, $data); $xlWS->getDefaultRowDimension()->setRowHeight(-1); $numcols = count(array_keys($data[0])); for ($lastcol = 'A', $i = 1; $i < $numcols; $i++) { $lastcol++; } $lastrow = count($data) + 1; // Format the last column (errors) $xlWS->getColumnDimension($lastcol)->setAutoSize(false)->setWidth(75); $xlWS->getStyle($lastcol . '1:' . $lastcol . $lastrow)->getAlignment()->setWrapText(true); // Auto row height /* This doesn't seem to work //$xlWS->getDefaultRowDimension()->setRowHeight(-1); foreach($xlWS->getRowDimensions() as $row) { $row->setRowHeight(-1); } */ return $xlWS; }
<?php /** * Excel export inscriptions boum * */ require_once 'core.php'; $xl = new ExcelBase('Boum ' . date('Y'), "Inscriptions à la Boum de l'Escalade " . date('Y'), 'boum'); $xl->setDefaultFontSize(10); // Process Enfants $sql = "SELECT * FROM " . VIEW_BOUM_ENFANTS; $qry = $db->query($sql); $xl->createWorksheet('Enfants', $qry->fetchAll()); // Process Parents $sql = "SELECT * FROM " . VIEW_BOUM_PARENTS; $qry = $db->query($sql); $xl->createWorksheet('Parents', $qry->fetchAll()); // Process Totals $sql = "SELECT * FROM " . VIEW_BOUM_TOTAUX; $qry = $db->query($sql); $xl->createWorksheet('Totaux', $qry->fetchAll()); $xl->workbook->setActiveSheetIndex(0); $xl->saveExcel();