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

相关推荐
V1ncent Chen9 分钟前
MySQL 插入更新语句(insert…on duplicate key update语句 )
数据库·sql·mysql
web1508509664114 分钟前
给SQL server数据库表字段添加注释SQL,附修改、删除注释SQL及演示
数据库·sql·oracle
qwy71522925816315 分钟前
20-R 绘图 - 饼图
开发语言·数据库·r语言
北京-宏哥34 分钟前
Linux系统安装MySQL5.7(其他版本类似)避坑指南
linux·运维·服务器
qw9491 小时前
Linux 高级篇 日志管理、定制自己的Linux系统、备份与恢复
linux·运维·服务器
littleBoy7771 小时前
使用excel中的VBA合并多个excel文件
excel·vba
guihong0041 小时前
深入理解Redis:从线程模型到应用场景的全面解析
数据库·redis·缓存
Suk-god1 小时前
【Redis原理】底层数据结构 && 五种数据类型
数据结构·数据库·redis
-SGlow-2 小时前
Linux相关概念和易错知识点(30)(线程互斥、线程同步)
linux·运维·服务器
小白教程2 小时前
Python连接MySQL数据库图文教程,Python连接数据库MySQL入门教程
数据库·python·mysql·python链接数据库·python链接mysql