Skip to content

5. 表格设置

ogenes edited this page Apr 23, 2023 · 2 revisions

表格设置

1. 宽度

可以直接设置默认宽度

$client->setStyleWidth(50);
$client->setStyleUnit('');

分别设置每列的宽度在 config 中设置 width 属性即可。

$config['sheet1'] = [
  ['bindKey' => 'goodsName', 'columnName' => '商品名称', 'width' => 40 ],
  ['bindKey' => 'price', 'columnName' => '售价', 'format' => NumberFormat::FORMAT_DATE_YYYYMMDDSLASH],
  ['bindKey' => 'actualStock', 'columnName' => '实际库存'],
];

2. 冻结表头

$client->setFreezeHeader(true);

3. 自动筛选

$client->setAutoFilter(true);

image-20220620105722294

4. 保护

$client->serProtection(true);

5. 使用redis

这里非必要不建议使用自定义缓存,自定义缓存会导致导出变慢,且一定不要用主业务的redis,如果导出过程中程序异常终止,phpspreadsheet不会释放redis空间,

$redis = new Redis();
$redis->connect('redis');
$client->setRedis($redis);
Clone this wiki locally