duanliu6083
2018-06-19 17:57
浏览 433
已采纳

PHPSpreadsheet - excel工作表中具有“格式为表格”的多个表

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.

If i run the code:

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);

The formation is not overtaken to the new Age.xlsx file.

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');

Only the last range will be set.

My questions are:

  1. Is it possible to have more then one table in a worksheet using PHPSpreadsheet?
  2. How can I realize this kind of output shown above?

Version

  • Excel MS Excel 2013
  • PHPSpreadsheet [1.2.1] - 2018-04-10

图片转代码服务由CSDN问答提供 功能建议

我尝试在一个工​​作表中使用多个格式化表。 该模板如下例所示:模板

表格采用表格格式模板。

如果我运行代码:

 使用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。'不存在'); 
} 
 $ reader = IOFactory :: createReader($ inputFileType); 
 $ spreadsheet = $ reader-> load(  $ inputFileName); 
 
 $ writer = new Xlsx($ spreadsheet); 
 $ writer-> save(Age.xlsx); 
 $ spreadsheet-> disconnectWorksheets(); 
unset($ spreadsheet);  
   
 
 

编队不会超越新的Age.xlsx文件。

如果我尝试手动设置表格,我会遇到AutoFilter的问题。 它接缝只能设置一个过滤范围。 我尝试了以下代码:

  $ ageSheet = $ spreadsheet-> getSheet(0); 
 $ ageSheet-> setAutoFilter('A3:B10'); 
  $ ageSheet-> setAutoFilter( 'D3:E9'); 
 $的ageSheet-> setAutoFilter( 'A17:B24'); 
 $的ageSheet-> setAutoFilter( 'D17:E23'); 
   
 
 

只会设置最后一个范围。

我的问题是:

    < li>使用PHPSpreadsheet在工作表中是否可以有多个表?
  1. 如何实现上面显示的这种输出? \ n

    版本

    • Excel MS Excel 2013
    • PHPSpreadsheet [1.2.1] - 2018-04-10
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhao8456 2018-07-11 06:37
    已采纳

    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 uses the table filtering and overrides the filtering every time by use of the setAutoFilter method. That means onlyone per worksheet is posible.

    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.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题