小编给大家分享一下PHPSpreadsheet导出excel超过26列怎么办,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!excel 行列表示方式xexcel 的列的表示规则从 A,B,C 一直到 Z,当超过 26 个字母
小编给大家分享一下PHPSpreadsheet导出excel超过26列怎么办,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
excel 行列表示方式
xexcel 的列的表示规则从 A,B,C 一直到 Z,当超过 26 个字母的时候用两个字母进行表示:AA,AB,AC…AZ,BA,BB,BC…BZ…,当超过 702 时又是另外一个种表示方法。
行的表示就是 1,2,3,4,5,6,7…. 这样下去。在 phpexcel 中要设一个单元格的值通过 setCellValue 方法就可以了,其中第一个参数表示列和行的拼接的值,如:A1,B1,AA1,BA1 这样。
知道这个之后,只要根据 $i/26 的整数部分和模部分计算出列的表示字母就可以了。
下面是解决方法
<?phpnamespace AppLibrariesExcel;use PhpOfficePhpSpreadsheetCellDataType;use PhpOfficePhpSpreadsheetSpreadsheet;use PhpOfficePhpSpreadsheetWriterXlsx;class Export{ protected $data_type; protected $spread_sheet; protected $x_lsx; public function __construct(DataType$data_type, Spreadsheet$spread_sheet, Xlsx$x_lsx) { $this->data_type= $data_type; $this->spread_sheet= $spread_sheet; $this->x_lsx= $x_lsx; } public function export($field_name,$data,$field_column,$file_name,$field_numeric_keys= []) { @ob_clean(); if (empty($field_name)|| empty($field_column)|| empty($data)|| empty($file_name))return false; $sheet= $this->spread_sheet->getActiveSheet(); //设置header $i= 0; foreach ($field_name as $value) { $cellName= self::stringFromColumnIndex($i). "1"; $sheet->setCellValue($cellName, $value)->calculateColumnWidths(); $sheet->getColumnDimension(self::stringFromColumnIndex($i))->setWidth(15); $i++; } //设置value $len= count($field_column); foreach ($data as $key=> $item) { $row= 2 + ($key* 1); for ($i= 0; $i< $len; $i++) { $sheet->setCellValueExplicit(self::stringFromColumnIndex($i). $row, $item[$field_column[$i]]??"", DataType::TYPE_STRING); if (isset($item[$field_column[$i]])&& !empty($field_numeric_keys)&& in_array($field_column[$i],$field_numeric_keys)) { $sheet->setCellValueExplicit(self::stringFromColumnIndex($i). $row, $item[$field_column[$i]]??"", DataType::TYPE_NUMERIC); } } } $writer= new Xlsx($this->spread_sheet); header('Content-Type: application/vnd.openxmlfORMats-officedocument.spreadsheetml.sheet');//告诉浏览器输出07Excel文件 header('Content-Disposition: attachment;filename="' . $file_name . '.xlsx"');//告诉浏览器输出浏览器名称 header('Cache-Control: max-age=0'); $writer->save('php://output'); @ob_flush(); @flush(); exit; } public static function stringFromColumnIndex($pColumnIndex = 0) { static $_indexCache= array(); if (!isset($_indexCache[$pColumnIndex])) { if ($pColumnIndex < 26) { $_indexCache[$pColumnIndex]= chr(65 + $pColumnIndex); }elseif ($pColumnIndex < 702) { $_indexCache[$pColumnIndex]= chr(64 + ($pColumnIndex / 26)). chr(65 + $pColumnIndex % 26); }else { $_indexCache[$pColumnIndex]= chr(64 + (($pColumnIndex - 26)/ 676)). chr(65 + ((($pColumnIndex - 26)% 676)/ 26)). chr(65 + $pColumnIndex % 26); } } return $_indexCache[$pColumnIndex]; }}
看完了这篇文章,相信你对“PHPSpreadsheet导出Excel超过26列怎么办”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网PHP编程频道,感谢各位的阅读!
--结束END--
本文标题: PHPSpreadsheet导出Excel超过26列怎么办
本文链接: https://www.lsjlt.com/news/306996.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0