Yii2,Kartik出口的自定义css样式

时间:2017-01-18 02:07:50

标签: gridview yii2 kartik-v

我正在尝试将自定义css样式应用于导出的文件,例如pdf。

例如,如何在pdf导出中应用自定义CSS样式?

我在styleOptions中更改了一些字体样式,但没有任何结果。

        <?= ExportMenu::widget([
        'target' => ExportMenu::TARGET_SELF,
        'dataProvider' => $dataProvider,
        'columns' => $report_columns,
        'fontAwesome' => true,
        'dropdownOptions' => [
            'label' => Yii::t('app','Export All'),
            'class' => 'btn btn-default'
        ],
        'styleOptions' => [
            'font' => [
                'size' => '24px',
                'bold' => true,
                'color' => [
                    'argb' => 'FFFFFFFF',
                ],
            ],
            'fill' => [
                'type' => PHPExcel_Style_Fill::FILL_SOLID,
                'color' => [
                    'argb' => '00000000',
                ],
            ],          
        ],
        'exportConfig' => [

            ExportMenu::FORMAT_CSV => false,
            ExportMenu::FORMAT_EXCEL => false,
            ExportMenu::FORMAT_EXCEL_X => false,
            ExportMenu::FORMAT_TEXT => false,
            //ExportMenu::FORMAT_PDF => false,
            //ExportMenu::FORMAT_HTML => false
        ]
        ]) . "<hr>\n".
        GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => $columns,
            'pjax' => true,
            'summary' => '',
            'options' => ['class' => 'xxx', 'style'=>'padding-right:10px']
        ]);
    ?>

1 个答案:

答案 0 :(得分:0)

必须将styleOptions设置为关联数组,因为它在导出菜单中的styleOptions设置文档中进行了更新: http://demos.krajee.com/export#option-styleOptions

'styleOptions' => [
    ExportMenu::FORMAT_EXCEL_X => [
        'font' => [
            'size' => '24px',
            'bold' => true,
            'color' => [
                'argb' => 'FFFFFFFF',
            ],
        ],
        'fill' => [
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => [
                'argb' => '00000000',
            ],
        ],
    ],
],

并确保您正确导入PHPExcel_Style_Fill。