setAutoSize_demo.php 579 B

12345678910111213141516171819202122
  1. <?php
  2. /**
  3. * 单元格自适应demo
  4. */
  5. require_once(__DIR__ . '/../vendor/autoload.php');
  6. use Pxlswrite\Pxlswrite;
  7. $fileObj = new Pxlswrite(['path' => __DIR__ . '/uploads']);
  8. $fileObj->fileName("setAutoSize.xlsx")
  9. ->field([
  10. 'username' => ['name' => '用户名'],
  11. 'age' => ['name' => '年龄'],
  12. ])
  13. ->setGeneralData(function () {
  14. yield [
  15. ['username' => '焚膏继晷焚膏继晷', 'age' => 15],
  16. ['username' => '演员', 'age' => 15],
  17. ];
  18. })
  19. ->setAutoSize(['A'])//单元格自适应列宽
  20. ->output();