PHP导出/导入Excel 扩展 XLSWriter
windows安装:
1.选择对应版本下载
https://pecl.php.net/package/xlswriter
https://pecl.php.net/package/xlswriter/1.3.7/windows
2.解压
3.将php_xlswriter.dll、php_xlswriter.pdb放在PHP的ext目录
4.在php.ini中增加extension=xlswriter
5.重启php【或站点】
Linux 安装:
1.下载:https://pecl.php.net/package/xlswriter
wget https://pecl.php.net/get/xlswriter-1.3.7.tgz
2.解压下载包
tar -zxvf xlswriter-1.3.7.tgz
3.进入文件夹,编译
cd xlswriter-1.3.7
phpize
./configure --with-php-config=/usr/local/php7.1/bin/php-config --enable-reader
make&&make install
- 导出文件
$config = [
'path' => '/home/viest' // xlsx文件保存路径
];
$excel = new \Vtiful\Kernel\Excel($config);
// fileName 会自动创建一个工作表,你可以自定义该工作表名称,工作表名称为可选参数
$filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
->header(['Item', 'Cost'])
->data([
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
])
->output();
- 导入文件
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
// 导出测试文件
$filePath = $excel->fileName('tutorial.xlsx')
->header(['Item', 'Cost'])
->output();
// 读取测试文件
$data = $excel->openFile('tutorial.xlsx')
->openSheet()
->getSheetData();
var_dump($data); // [['Item', 'Cost']]
本文来自博客园,作者:只要AD钙奶,转载请注明原文链接:https://www.cnblogs.com/carver/articles/16633176.html

浙公网安备 33010602011771号