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

相关推荐
简鹿办公18 分钟前
Excel 表格内批量添加前缀与后缀的实用方法
excel·excel单元格统一加后缀文字
炸毛的飞鼠26 分钟前
智警杯备赛--excel模块
excel
Mintimate37 分钟前
云服务器 Linux 手动 DD 安装第三方 Linux 发行版:原理与实战
linux·运维·服务器
RussellFans1 小时前
Linux 环境配置
linux·运维·服务器
网硕互联的小客服1 小时前
503 Service Unavailable:服务器暂时无法处理请求,可能是超载或维护中如何处理?
服务器·git·github
高冷的肌肉码喽2 小时前
Linux-进程间的通信
linux·运维·服务器
敖云岚2 小时前
【Redis】分布式锁的介绍与演进之路
数据库·redis·分布式
jekc8682 小时前
禅道18.2集成LDAP
linux·运维·服务器
LUCIAZZZ2 小时前
HikariCP数据库连接池原理解析
java·jvm·数据库·spring·springboot·线程池·连接池
我在北京coding2 小时前
300道GaussDB(WMS)题目及答案。
数据库·gaussdb