1. 普通模式
先data方法在工作表中插入数据,再设置某列或者某行样式
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('tutorial.xlsx');
$fileHandle = $fileObject->getHandle();
// 使用 扩展自带颜色常量 创建样式资源
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
// 使用 RGB16进制数 创建样式资源
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(0xFF69B4)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $colorStyle) // 应用样式
->output();
2. 固定内存
可以根据 insertText 方法 第四个参数 设置某个单元格样式
->toResource() 之前可以 \Vtiful\Kernel\Format::class 中设置需要的各种组合的格式
例如
$format
->italic()// 斜体
->align(Format::FORMAT_ALIGN_CENTER, Format::FORMAT_ALIGN_VERTICAL_CENTER)// 对齐
->strikeout()// 文本删除(文本中间划线)
->underline(Format::UNDERLINE_SINGLE)// 下划线
->toResource();
样式列表:https://xlswriter-docs.viest.me/zh-cn/yang-shi-lie-biao
示例:
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->constMemory('tutorial.xlsx')->header(['name', 'age']);
$fileHandle = $fileObject->getHandle();
// 使用 扩展自带颜色常量 创建样式资源
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
// 使用 RGB16进制数 创建样式资源
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(0xFF69B4)->toResource();
$list = [
['viest', 21],
['wjx', 21]
];
foreach ($list as $k => $v) {
foreach ($v as $k1 => $v1) {
$fileObject->insertText($k + 1, $k1, $v1, null, $colorStyle);
}
}
$filePath = $fileObject->output();