全局默认样式

优质
小牛编辑
125浏览
2023-12-01

设置全局默认样式,将会影响所有写入单元格的样式;

函数原型
defaultFormat(resource $formatHandler)

resource $formatHandler
$config = ['path' => './tests'];
$excel  = new \Vtiful\Kernel\Excel($config);
​
$excel->fileName('tutorial.xlsx');
​
$format        = new \Vtiful\Kernel\Format($excel->getHandle());
$colorOneStyle = $format
    ->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)
    ->border(\Vtiful\Kernel\Format::BORDER_DASH_DOT)
    ->toResource();
​
$format        = new \Vtiful\Kernel\Format($excel->getHandle());
$colorTwoStyle = $format
    ->fontColor(\Vtiful\Kernel\Format::COLOR_GREEN)
    ->toResource();
​
$filePath = $excel
    // Apply the first style as the default
    ->defaultFormat($colorOneStyle)
    ->header(['hello', 'xlswriter'])
    // Apply the second style as the default style
    ->defaultFormat($colorTwoStyle)
    ->data([
        ['hello', 'xlswriter'],
    ])
    ->output();