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

不知道php-config在哪请使用find / -name php-config查找

find / -name php-config

4.在php.ini文件增加 extension=xlswriter.so

extension=xlswriter.so

5.重启php服务

使用说明

说明文档:https://xlswriter-docs.viest.me/zh-cn

1.导出文件

$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();

2.导入文件

$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']]
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值