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']]

作者:Carver-大脸猫

出处:https://www.cnblogs.com/carver/articles/16633176.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请注明原处

posted @   Carver-大脸猫  阅读(804)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu