I'm doing a manual query. You can translate the names of the columns easily, but I can not do it with the results of the columns in a slightly more efficient way. The results are printed in excel with the help of yii2tech\spreadsheet\Spreadsheet
.
Preparing query
$columns = [
[
'attribute' => 'description',
'label' => Yii::t('data', 'Description')
],
[
'attribute' => 'type',
'label' => Yii::t('data', 'Type')
]
];
$query
->addSelect(['description' => 'data.description'])
->addSelect(['type' => 'data.type'])
->from('data')
$rows = $query->all();
So far I make the query. The following is my way of translating the results of the type
column. Because they can be just some values.
Translating results
foreach ($rows as $key => $row) {
$rows[$key]['type'] = Yii::t('data', $row['type']);
}
This data is exported to xls format:
Exporting results
$exporter = new Spreadsheet([
'dataProvider' => new ArrayDataProvider([
'allModels' => $rows,
]),
'columns' => $columns,
]);