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

相关推荐
m0_640309301 分钟前
如何将 sticky 元素精确定位到父容器的右上角
jvm·数据库·python
m0_3776182313 分钟前
c++如何将双精度浮点数以科学计数法写入文件_scientific标志【详解】
jvm·数据库·python
weixin_4249993616 分钟前
如何检测SQL注入风险_利用模糊测试技术发现漏洞
jvm·数据库·python
2301_7751481520 分钟前
如何用正则具名捕获组 (-) 提升复杂数据的提取效率
jvm·数据库·python
2501_9142459324 分钟前
Go语言如何在VSCode中开发_Go语言VSCode配置教程【避坑】.txt
jvm·数据库·python
2301_7826591827 分钟前
MongoDB如果有一个分片完全宕机集群还能用吗_受影响数据的不可读与分片隔离感知
jvm·数据库·python
justjinji28 分钟前
JavaScript中严格模式use-strict对引擎解析的辅助
jvm·数据库·python
Absurd58731 分钟前
CSS如何使用-default获取默认选项样式_通过状态伪类突出预选表单项
jvm·数据库·python
风吹迎面入袖凉36 分钟前
【Redis】Redis缓存击穿
数据库·redis·缓存
weixin_4585801238 分钟前
CSS如何让flex布局支持老版本浏览器_添加-webkit-前缀与兼容性写法
jvm·数据库·python