返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >phpspreadsheet导出excel自动获得列,数字下标
  • 339
分享到

phpspreadsheet导出excel自动获得列,数字下标

excel服务器数据库 2023-09-05 22:09:11 339人浏览 八月长安
摘要

安装composer require phpoffice/phpspreadsheetuse PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\

安装composer require phpoffice/phpspreadsheetuse PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\Xlsx;use PhpOffice\PhpSpreadsheet\Style\Border;$spreadsheet = new Spreadsheet();$sheet = $spreadsheet->getActiveSheet();//从65开,65是第1列,66是第二列,2是第二行$sheet->setCellValue(strtoupper(chr(65)) . '1', '大得');$sheet->setCellValue(strtoupper(chr(66)) . '1', '大得');$sheet->setCellValue(strtoupper(chr(66)) . '2', '大2');header('Content-Type: application/vnd.ms-excel');header('Content-Disposition: attachment;filename=/www/wwwroot/swoole/erp-test-zhoao2/excel/666.xlsx"');header('Cache-Control: max-age=0');$writer = new Xlsx($spreadsheet);$date = date("Ymd");$Absolute_Path=$_SERVER['SCRIPT_FILENAME'];$user_path = substr($Absolute_Path,0,-9)."storage/cdjdade/{$date}";//保存路径if(!is_dir($user_path)){     mkdir($user_path);}$writer->save($user_path.'/666.xlsx');//删除清空:$spreadsheet->disconnectWorksheets();unset($spreadsheet);

报错Invalid cell coordinate [1,下标超过26个字母

$spreadsheet = new Spreadsheet();        $sheet = $spreadsheet->getActiveSheet();        $sheet->setCellValue(strtoupper(chr(65)) . '1', '部门');        $sheet->setCellValue(strtoupper(chr(66)) . '1', '员工');        $sheet->setCellValue(strtoupper(chr(67)) . '1', '入职日期');        $sheet->setCellValue(strtoupper(chr(68)) . '1', '岗位');        $sheet->setCellValue(strtoupper(chr(69)) . '1', '职位');        for ($i=1;$i<=$day;$i++){            $s = round(69+$i);            if($s<91){                $sheet->setCellValue(strtoupper(chr($s)) . '1', $i);            }else{                //超过26个字母,在此超过B                $s = $s-26;                $sheet->setCellValue(chr(ord("A")).strtoupper(chr($s)) . '1', $i);            }        }        header('Content-Type: application/vnd.ms-excel');        header('Content-Disposition: attachment;filename=/www/wwwroot/swoole/erp-test-zhoao2/excel/666.xlsx"');        header('Cache-Control: max-age=0');        $writer = new Xlsx($spreadsheet);        $date = date("Ymd");        $Absolute_Path=$_SERVER['SCRIPT_FILENAME'];        $user_path = substr($Absolute_Path,0,-9)."storage/cdjdade/{$date}";//保存路径        if(!is_dir($user_path)){            mkdir($user_path);        }        $dates = date("YmdHis");        $writer->save($user_path."/$dates.xlsx");        //删除清空:        $spreadsheet->disconnectWorksheets();        unset($spreadsheet);

样式

https://blog.csdn.net/qq_34631220/article/details/130628902

来源地址:https://blog.csdn.net/qq_34631220/article/details/132543643

--结束END--

本文标题: phpspreadsheet导出excel自动获得列,数字下标

本文链接: https://lsjlt.com/news/396226.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作