php - Laravel:如何在使用模板文件导出时更改 startcell
问题描述
Laravel 框架 5.8.38
maatwebsite/excel 3.1.19
我正在尝试使用模板文件导出。
以下代码正在运行,但“startCell()”似乎不起作用。
它总是从导出文件中的“A6”开始。
在这种情况下我该怎么办。
class TestExport implements FromQuery, WithEvents, WithCustomStartCell, WithStrictNullComparison
{
public function setTemplate(string $template_file)
{
if (file_exists($template_file)) {
$this->template_file = $template_file;
}
return $this;
}
public function startCell(): string
{
return 'A3';
}
public function registerEvents(): array
{
return [
BeforeExport::class => function (BeforeExport $event) {
if (is_null($this->template_file)) {
return;
}
$event->writer->reopen(new LocalTemporaryFile($this->template_file), Excel::XLSX);
$event->writer->getSheetByIndex(0);
$this->calledByEvent = true;
$event->writer->getSheetByIndex(0)->export($event->getConcernable());
return $event->getWriter()->getSheetByIndex(0);
},
BeforeWriting::class => function (BeforeWriting $event) {
$event->writer->removeSheetByIndex(1);
return;
},
];
}
}
解决方案
推荐阅读
- swift - 带有动画的文本字段四边边框
- javascript - 如何避免Angular中ngModelChange上的“TypeError:无法读取未定义的属性'长度'”
- python - OpenCV 问题:FileNotFoundError: [WinError 2] 系统找不到指定的文件
- angular - 如何在 Angular 6 中使用 pbkdf2_sha256 算法加密密码
- java - Java从文本文件中替换字符串中的一个单词
- rest - 在使用 Multer 将文件上传到文件夹之前删除和创建文件夹
- ios - 当 HTTP 请求命中并且应用程序突然进入后台时,iOS 12 URLSession 中断
- spring - 找不到类 org.springframework.web.context.support.XmlWebApplicationContext 在 EAP 上的 Fuse 7.1.0 中部署 WAR
- vba - 通过 VBA 中的操作查询获取受影响记录的数量
- node.js - Nodejs,如果节点忙,请求在哪里排队?