PhpSpreadsheet设置单元格常用操作汇总(2)

<?php require 'vendor/autoload.php'; $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('tmp.xlsx'); $sheet = $spreadsheet->getActiveSheet(); $data = $sheet->toArray(); var_dump($data);

导出:

<?php require 'vendor/autoload.php'; $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getDefaultColumnDimension()->setWidth(40); $sheet->getColumnDimensionByColumn(2)->setWidth(100); $sheet->setCellValue('A2', 'Hello World !'); for ($i = 1; $i < 10; $i++) { $sheet->setCellValueByColumnAndRow($i, 1, 'Col'.$i); } $fileName = '01simple.xlsx'; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="'. $fileName .'"'); header('Cache-Control: max-age=0'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); $writer->save('php://output'); exit;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4a549182f31818023e2f33e8525cbe96.html