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

相关推荐
城南云小白11 分钟前
Linux网络服务只iptables防火墙工具
linux·服务器·网络
从心归零12 分钟前
sshj使用代理连接服务器
java·服务器·sshj
咩咩大主教13 分钟前
C++基于select和epoll的TCP服务器
linux·服务器·c语言·开发语言·c++·tcp/ip·io多路复用
isNotNullX13 分钟前
一文解读OLAP的工具和应用软件
大数据·数据库·etl
羌俊恩18 分钟前
视频服务器:GB28181网络视频协议
服务器·网络·音视频
运维小白。。42 分钟前
Nginx 反向代理
运维·服务器·nginx·http
科技互联人生1 小时前
中国数据中心服务器CPU行业发展概述
服务器·硬件架构
小诸葛的博客2 小时前
pg入门1——使用容器启动一个pg
数据库
KookeeyLena52 小时前
云手机可以挂在服务器使用吗?
运维·服务器·智能手机