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

复制代码
安装

composer require phpoffice/phpspreadsheet



use 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

相关推荐
RestCloud2 小时前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术5 小时前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
christine-rr8 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
可涵不会debug9 小时前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom9 小时前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*9 小时前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
東雪蓮☆9 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
Slaughter信仰9 小时前
深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)第十章知识点问答(10题)
java·jvm·数据库
麦兜*9 小时前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring