采用composer 安装
文档地址
[https://phpspreadsheet.readthedocs.io/en/latest/](https://phpspreadsheet.readthedocs.io/en/latest/)
安装方法
composer require phpoffice/phpspreadsheet
```
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
/**
导入
**/
function get_excel($uploadfile)
{
$inputFileType = IOFactory::identify($uploadfile); //传入Excel路径
$excelReader = IOFactory::createReader($inputFileType); //Xlsx
$PHPExcel = $excelReader->load($uploadfile); // 载入excel文件
$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
$sheetdata = $sheet->toArray();//返回数组
var_dump($sheetdata);exit;
}
/**
* 导出
* $article=Db("article")->field("id,title,FROM_UNIXTIME(create_time,'%Y/%m/%d')")->select();
* $title=array("编号","标题","添加时间");
* $excel_title = 'download.xlsx';
* download($title,$title,$article);
*/
public function download($filename, $title, $data)
{
try {
if (!is_array($title) || count($title) <= 0) {
return false;
}
$spreadsheet = new Spreadsheet();
foreach ($title as $key => $one) {//设置标题栏目
$spreadsheet->setActiveSheetIndex(0)->setCellValueByColumnAndRow($key + 1, 1, $one);//列,行,值
}
foreach ($data as $key => $one) {//设置内容
$i = 1;
foreach ($one as $ckey => $cone) {
$spreadsheet->setActiveSheetIndex(0)->setCellValueByColumnAndRow($i, $key + 2, $cone);//列,行,值
$i++;
}
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');//告诉浏览器输出07Excel文件
header('Content-Disposition: attachment;filename="' . $filename . '"');//告诉浏览器输出浏览器名称
header('Cache-Control: max-age=0');//禁止缓存
$writer->save('php://output');
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
} catch (\Exception $e) {
$this->error = $e;
return 0;
}
}
```
- ThinkPHP
- MySql
- 事务
- 漏洞修复
- jQuery
- select搜索下拉框,多选,全选等
- 移动端富文本编辑器
- 复制内容
- ajax请求
- PHP
- 基本语法
- 关于屏蔽“未定义数组下标:0”错误的问题
- PHP文件操作
- 使用PhpOffice 在PHP7.3中导出数据报错问题
- curl
- PHP生成PPT
- Redis
- 如何在PHP中安装Redis扩展
- Redis队列,秒杀,抢购
- 压力测试(ab)
- apache ab压力测试
- 微信
- 微信支付
- 微信分享
- 授权登录
- 微信公众号服务器
- 自动回复
- 微信发起支付html页面
- composer
- 安装
- 二维码的生成
- Excel导入导出
- 数据采集
- 采集列表
- 采集内容详情
- 图片采集
- Linux
- 常用命令
- 解压压缩
- 服务器
- 服务器运行缓慢的原因
- IIS 隐藏index.php
- 端口检测
- Nginx
- 数据库
- Oracle数据库
- MySql
- 新增MySql
- Field字段
- Tp验证码加载不出来,解决办法
- API接口
- Google API
- 织梦CMS支付接口
- SMTP发送邮箱问题
- Could not connect to SMTP host
- 阿里云API接口
- 支付宝新版配置
- 腾讯API接口
- 安装方法
- 百度地图API
- 通过ip地址获取当前城市
- 常用笔记
- yarn