function render($data) { $tournament = $data['tournament']; $disciplines = $data['disciplines']; $header = ['Event' => 'string', 'SpielerID' => 'string', 'Name' => 'string', 'Vorname' => 'string', 'Verein' => 'string', 'Geschlecht' => 'string', 'Email' => 'string', 'Partner ID' => 'string', 'Setzplatz' => 'string']; $output = []; foreach ($disciplines as $d) { $dname = $d->name; // Fix up discipline names if (\preg_match('/^H([DE]) U0?([0-9]+)$/', $dname, $m)) { $dname = 'J' . $m[1] . ' U' . $m[2]; } elseif (\preg_match('/^D([DE]) U0?([0-9]+)$/', $dname, $m)) { $dname = 'M' . $m[1] . ' U' . $m[2]; } elseif (\preg_match('/^(DD|DE|GD|HD|HE|MX)-?\\s*([A-Z])$/', $dname, $m)) { $dname = $m[1] . $m[2]; } $is_doubles = $d->with_partner(); foreach ($d->entries as $er) { if ($er['on_waiting_list']) { continue; } if ($is_doubles && $er['partner'] === NULL) { continue; } \array_push($output, [$dname, $er['player']->textid, $er['player']->get_lastname(), $er['player']->get_firstname(), $er['player_club']->name, $er['player']->gender, $er['player']->email, $is_doubles ? $er['partner']->textid : '', $er['seeding']]); if ($is_doubles) { \array_push($output, [$dname, $er['partner']->textid, $er['partner']->get_lastname(), $er['partner']->get_firstname(), $er['partner_club']->name, $er['partner']->gender, $er['partner']->email, $is_doubles ? $er['player']->textid : '', $er['seeding']]); } } } $writer = new \XLSXWriter(); $writer->writeSheet($output, 'Meldungen', $header); $safe_filename = \bmtmgr\utils\sanitize_filename($tournament->name); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="' . $safe_filename . '.xlsx"'); echo $writer->writeToString(); }
$sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true)); $sClassDisplayName = MetaModel::GetName($sClassName); $sDisposition = utils::ReadParam('disposition', 'inline'); if ($sDisposition == 'attachment') { switch ($sFormat) { case 'xlsx': $oPage = new ajax_page(""); $oPage->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $oPage->SetContentDisposition('attachment', $sClassDisplayName . '.xlsx'); require_once APPROOT . '/application/excelexporter.class.inc.php'; $writer = new XLSXWriter(); $writer->setAuthor(UserRights::GetUserFriendlyName()); $aHeaders = array(0 => explode(',', $sResult)); // comma is the default separator $writer->writeSheet($aHeaders, $sClassDisplayName, array()); $oPage->add($writer->writeToString()); break; case 'csv': default: $oPage = new CSVPage(""); $oPage->add_header("Content-type: text/csv; charset=utf-8"); $oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\""); $oPage->no_cache(); $oPage->add($sResult); } } else { $oPage = new ajax_page(""); $oPage->no_cache(); $oPage->add('<p style="text-align:center">'); $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&class_name=' . $sClassName . '"><img border="0" src="../images/csv.png"><br/>' . $sClassDisplayName . '.csv</a></div>'); $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&format=xlsx&class_name=' . $sClassName . '"><img border="0" src="../images/xlsx.png"><br/>' . $sClassDisplayName . '.xlsx</a></div>');
public function GetFooter() { $hFile = @fopen($this->aStatusInfo['tmp_file'], 'rb'); if ($hFile === false) { throw new Exception('ExcelBulkExport: Failed to open temporary data file: "' . $this->aStatusInfo['tmp_file'] . '" for reading.'); } $sHeaders = fgets($hFile); $aHeaders = json_decode($sHeaders, true); $aData = array(); while ($sLine = fgets($hFile)) { $aRow = json_decode($sLine); $aData[] = $aRow; } fclose($hFile); $fStartExcel = microtime(true); $writer = new XLSXWriter(); $writer->setAuthor(UserRights::GetUserFriendlyName()); $aHeaderTypes = array(); $aHeaderNames = array(); foreach ($aHeaders as $Header) { $aHeaderNames[] = $Header['label']; $aHeaderTypes[] = $Header['type']; } $writer->writeSheet($aData, 'Sheet1', $aHeaderTypes, $aHeaderNames); $fExcelTime = microtime(true) - $fStartExcel; //$this->aStatistics['excel_build_duration'] = $fExcelTime; $fTime = microtime(true); $data = $writer->writeToString(); $fExcelSaveTime = microtime(true) - $fTime; //$this->aStatistics['excel_write_duration'] = $fExcelSaveTime; @unlink($this->aStatusInfo['tmp_file']); return $data; }
public function crudListExcel($model, $scope) { $obj = CrudModel::createInstance($model, $scope); $params = $this->request->all(); $cols = $obj->getList()->getParam('columns'); $xls = []; $row = []; foreach ($cols as $col) { if ((empty($col['ctype']) || $col['ctype'] != 'checkbox') && $col['data'] != 'actions' && empty($col['invisible'])) { $row[] = $col['title']; } } $xls[] = $row; $query = $this->app['session']->get('current_query_info'); if (empty($query) || !isset($query['sql']) || !isset($query['bind'])) { $q = CrudModelCollectionBuilder::createDataTables($obj, $params)->applyContextFilter()->getCollectionQuery()->getQuery(); $query = ['sql' => $q->toSQL(), 'bind' => $q->getBindings()]; } $rs = \DB::select($query['sql'], $query['bind']); foreach ($rs as $r) { $row = []; foreach ($cols as $col) { if ((empty($col['ctype']) || $col['ctype'] != 'checkbox') && $col['data'] != 'actions' && empty($col['invisible'])) { $row[] = $r[$col['data']] ?? ''; } } $xls[] = $row; } $writer = new \XLSXWriter(); $writer->writeSheet($xls, 'Sheet1'); $data = $writer->writeToString(); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); //keeps ie happy header('Content-Disposition: attachment; filename=xls.xlsx'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Length: ' . strlen($data)); header('Content-Transfer-Encoding: binary'); echo $data; exit; }