Answer the question
In order to leave comments, you need to log in
How to set column width in excel export via kartik export menu?
Good day!
I'm exporting to excel using kartik/yii2-export and I can't set the column width:
ExportMenu::widget([
'dataProvider' => $dataProvider,
'exportConfig' => [
ExportMenu::FORMAT_TEXT => false,
ExportMenu::FORMAT_HTML => false,
ExportMenu::FORMAT_EXCEL => false,
ExportMenu::FORMAT_CSV => false,
],
'tableOptions' => [
'class' => 'table table-striped table-responsive'
],
'columns' => $gridColumns,
'onRenderSheet' => function($sheet, $widget) {
$sheet->setCellValue("A5", "Бееееееееееее"); // работает
$sheet->getColumnDimension('A')->setWidth(240); // не работает
$sheet->setTitle('Вопросы руководителю'); // работает
}
]);
Answer the question
In order to leave comments, you need to log in
I'm sorry, I figured it out myself
ExportMenu::widget([
'dataProvider' => $dataProvider,
'exportConfig' => [
ExportMenu::FORMAT_TEXT => false,
ExportMenu::FORMAT_HTML => false,
ExportMenu::FORMAT_EXCEL => false,
ExportMenu::FORMAT_CSV => false,
],
'tableOptions' => [
'class' => 'table table-striped table-responsive'
],
'columns' => $gridColumns,
'autoWidth' => false, // Ключевой момент, автоматическую установку ширины нужно сбросить
'onRenderSheet' => function($sheet, $widget) {
$sheet->setCellValue("A5", "Бееееееееееее");
$sheet->getColumnDimension('A')->setWidth(50); // теперь все работает
$sheet->getColumnDimension('D')->setVisible(false);
$sheet->mergeCells('A4:E4');
$sheet->setTitle('Вопросы руководителю');
}
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question