当前位置: 首页 > news >正文

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

安装composer require phpoffice/phpspreadsheetuse 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

http://www.lryc.cn/news/146390.html

相关文章:

  • 结算日-洛谷
  • Android Native Code开发学习(一)环境配置
  • Python GUI应用程序开发之wxPython使用详解
  • 【电子学会真题】青少年软件编程(C语言)等级考试试卷(一级) 2021年9月
  • 学习完毕JavaSE的感想
  • FastJson的学习
  • python scrapy框架
  • 滑动窗口系列3-Leetcode134题加油站
  • LOIC(low orbit ion cannon)
  • 从格灵深瞳中报稳定盈利,看AI公司的核心竞争力
  • 理解 Databend Cluster key 原理及使用
  • C++day3(类、this指针、类中的特殊成员函数)
  • Qt中的配置文件:实现个性化应用程序配置与保存加载
  • Navicat激活时出现rsa public key not find错误
  • FFmpeg5.0源码阅读——URLContext和URLProtocol
  • Qt的输出
  • 长胜证券:久违普涨再现 大盘回升有望加速
  • WPF .NET 7.0学习整理(一)
  • 数据分析简介
  • 解读未知:文本识别算法的突破与实际应用
  • [第七届蓝帽杯全国大学生网络安全技能大赛 蓝帽杯 2023]——Web方向部分题 详细Writeup
  • el-backtop返回顶部的使用
  • Go 官方标准编译器中所做的优化
  • C语言程序设计——小学生计算机辅助教学系统
  • SQL自动递增的列恢复至从0开始
  • 介绍一下CDN
  • 2023年最新 Github Pages 使用手册
  • docker 安装 Nginx
  • 【NLP的python库(01/4) 】: NLTK
  • Java IDEA Web 项目 1、创建