Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
excelexporter.php
1<?php
2
4
13
14final class ExcelExporter
15{
16 public const REQUEST_PARAM_NAME = 'mode';
17 public const REQUEST_PARAM_VALUE = 'excel';
18
19 public function isExportRequest(?HttpRequest $request = null): bool
20 {
21 $request ??= Context::getCurrent()->getRequest();
22
23 return $request->get(self::REQUEST_PARAM_NAME) === self::REQUEST_PARAM_VALUE;
24 }
25
26 public function getControl(?HttpRequest $request = null): BaseButton
27 {
31 $request ??= Context::getCurrent()->getRequest();
32
33 $uri = new Uri($request->getRequestUri());
34 $uri->addParams([
35 self::REQUEST_PARAM_NAME => self::REQUEST_PARAM_VALUE,
36 // for disable composite
37 'ncc' => 1,
38 ]);
39
40 $button = new BaseButton();
41 $button->setLink((string)$uri);
42 $button->setText(Loc::getMessage('MAIN_GRID_EXPORT_EXCEL_BUTTON_TEXT'));
43
44 return $button;
45 }
46
47 public function process(Grid $grid, string $fileName = 'export'): void
48 {
49 global $APPLICATION;
50
55 $APPLICATION->RestartBuffer();
56
57 $grid->getSettings()->setMode(Settings::MODE_EXCEL);
58
59 try
60 {
61 ob_start();
62 $APPLICATION->IncludeComponent(
63 'bitrix:main.ui.grid',
64 'excel',
66 );
67 $content = ob_get_contents();
68 }
69 finally
70 {
71 ob_end_clean();
72 }
73
74 header('Content-Type: application/vnd.ms-excel');
75 header('Content-Disposition: filename="' . $fileName . '.xls"');
76
77 echo $content;
78
79 die();
80 }
81}
static getCurrent()
Definition context.php:241
static get(Grid $grid, array $additionParams=[])
isExportRequest(?HttpRequest $request=null)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29