问题描述
我尝试在一个工作表中包含多个格式化的表.该模板如下例所示:模板
I try to have multiple formatted tables in one worksheet. The template looks like following example: Template
表使用表格式模板设置样式.
The tables are styled with table format templates.
如果我运行代码:
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
$inputFileName = 'template/Age.xlsx';
$inputFileType = 'Xlsx';
if (!file_exists($inputFileName)) {
echo('File ' . $inputFileNameShort . ' does not exist');
}
$reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName);
$writer = new Xlsx($spreadsheet);
$writer->save(Age.xlsx);
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
该格式未覆盖到新的Age.xlsx文件中.
The formation is not overtaken to the new Age.xlsx file.
如果我尝试手动设置表格样式,则会遇到AutoFilter问题.似乎只能设置一个过滤器范围.我尝试了以下代码:
If I try to style the tables by hand, I run in an issue with the AutoFilter. It seams to be that only one filter range can be set. I tried following code:
$ageSheet =$spreadsheet->getSheet(0);
$ageSheet->setAutoFilter('A3:B10');
$ageSheet->setAutoFilter('D3:E9');
$ageSheet->setAutoFilter('A17:B24');
$ageSheet->setAutoFilter('D17:E23');
仅设置最后一个范围.
我的问题是:
- 是否可以使用PHPSpreadsheet在一个工作表中包含一个以上的表?
- 我如何实现上面显示的这种输出?
版本
- Excel MS Excel 2013
- PHPSpreadsheet [1.2.1]-2018-04-10
推荐答案
在MS excel中,只能设置一个真实的过滤器.要在工作表上放置多个内容,您必须使用格式模板.格式模板使用数据透视表来实现多重过滤器行为.
In MS excel can be set only one real filter. To have more then one on a Worksheet, you have to use format templates. Format templates uses pivot tables to realize the multifilter behavior.
PHPspreadsheet使用表过滤,每次使用setAutoFilter方法覆盖过滤.这意味着每个工作表只能有一个.
PHPspreadsheet uses the table filtering and overrides the filtering every time by use of the setAutoFilter method. That means onlyone per worksheet is posible.
目前,PHPspreadsheet中不支持数据透视表.
There is at the Moment no support of pivot tables in PHPspreadsheet.
目前,在一个工作表中不能再包含一个已过滤的表.
At the moment it is not possible to have more the one filtered table in one worksheet.
这篇关于PHPSpreadsheet-具有“格式为表格"的多个表格;在Excel工作表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!