php怎么获取下拉列框dataf的值,GitHub - fbenwu/phpspreadsheet: 简单操作excel文件(读取,导出)...

本文介绍了如何使用phpspreadsheet库来读取和导出Excel文件。示例包括读取单个和多个工作表,设置列宽以及一次性导出多个工作表的数据。该库提供了灵活的API,支持自定义表头、数据和导出格式。
摘要由CSDN通过智能技术生成

phpspreadshhet

phpspreadshhet 读取,导出

安装

composer require fan1992/phpspreadsheet

使用示例

use Fan1992\Phpspreadsheet\Excel;

$excel = new Excel();

读取文档(默认只读取第一个sheet)

$data = $excel->read('./test.xlsx');

print_r($data);

一次读取多个sheet

$excel->sheetNames = ['data_a'=>'表1','data_b'=>'表2','data_c'=>'Sheet3'];

$data = $excel->read('./test.xlsx');

print_r($data);

一次读取所有sheet

$excel = new Excel();

$excel->autoReadAllSheets = true;

$data = $excel->read('./test.xlsx');

print_r($data);

导出

$header = ['提提1', 'title2', '标题3', '测试测试']; //表头,即第一行

$data = [//具体数据,支持多维数组(合并单元格)

['12', ['阿斯顿发','asdf','2019-06-19'], '是的', '沙箱'],

['撒发顺丰的', ['1','23','撒旦法师'], '2019-06-19', 'asdasdfas']

];

$width = [30,0,40,60]; //列宽度,为0或没有则自动适应

$excel->export($data, $header,'test'.time(),null, 'mysheet', $width);

导出多个sheet

$excel1Data = [

'data' => [

['12', ['阿斯顿发', 'asdf', '2019-06-19'], '是的', '沙箱'],

['asd', ['阿斯顿发', '22', '2019-06-19'], '是', '沙asdf箱'],

],

'header' => ['header1', '标题2', '333', '超级长超级长超级长超级长超级长超级长超级长的标题'],

'sheetName' => '1211sheet1',

'width' => [5, 0, 5]

];

$excel2Data = [

'data' => [

['12', ['阿斯顿发', 'asdf', '2019-06-19'], '是的', '沙箱'],

['asd', ['阿斯顿发', '22', '2019-06-19'], '是', '沙asdf箱'],

],

'header' => ['header1', '标题2', '333', '超级长超222222级长超级长超级长超级长超级长超级长的标题'],

'sheetName' => '',

'width' => []

];

$excel3Data = [

'data' => [

['12', ['阿斯顿发', 'asdf', '2019-06-19'], '是的', '沙333箱'],

['asd', ['阿斯顿发', '22', '2019-06-19'], '是3333', '沙asdf箱'],

],

'header' => ['header1', '标题2', '333', '超级长超级长超3333级长超级长超级长超级长超级长的标题'],

'sheetName' => '导出sheet3',

'width' => []

];

$data = [$excel1Data, $excel2Data, $excel3Data];

$excel->mutiSheetExport($data, 'muti' . time(), Sheet::TYPE_XLSX);

其它

$readFirstLine = false;//是否读取首行

$down = true; //是否直接下载,false则保存文件在服务器上

支持导出格式:xls,xlsx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值