2

我正在尝试将自定义 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']
        ]);
    ?>
4

1 回答 1

1

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。

于 2019-06-01T22:21:53.607 回答