duncan3dc / phpexcel
1.3.0
2016-09-30 10:33 UTC
Requires
- php: ^5.6|^7.0
- phpoffice/phpexcel: ^1.8.1
Requires (Dev)
- phpunit/phpunit: ^5.5
README
PHPExcel 库的简单封装
静态方法
- read(string $filename[, mixed $key]): array - 读取电子表格并将其内容转换为数组(使用 PHPExcel toString() 方法)。默认情况下,这将返回一个枚举数组,每个元素代表一个工作表。可以通过传递 $key 参数请求特定的工作表,该参数可以是表示(基于零)工作表编号的整数,或表示工作表名称的字符串。
- getCellName(int $col, int $row): string - 将数字列号(基于零)和行号转换为单元格名称(例如 B3)
公共方法
- save(string $filename): null - 调用 PHPExcel_Writer_Excel2007 类的 save() 方法。
- output(string $filename): null - 将电子表格输出到浏览器以提示下载。
- addImage(string $cell, string $path): null - 在指定的单元格中添加图片。
- setCell(string $cell, mixed $value[, int $style]): null - 将单元格设置为值。$style 参数可用于在单元格上设置多个样式,使用以下类常量:BOLD ITALIC LEFT RIGHT CENTER
示例
Excel 类使用 duncan3dc 命名空间
use duncan3dc\Excel;
$excel = new Excel(); $excel->setCell("A1","Title", Excel::BOLD | EXCEL::CENTER); for($i = 1; $i < 10; $i++) { $cell = $excel->getCellName($i,1); $excel->setCell($cell,"Test " . $i); } for($i = 1; $i < 10; $i++) { $cell = Excel::getCellName($i,2); $excel->setCell($cell,"Value " . $i); } $excel->save("/tmp/text.xls");