GithubHelp home page GithubHelp logo

php-excel-export's Introduction

php-excel-export

PHPExcel from Array by cli or browser, support php5, php7, php8

通过命令行或者浏览器把PHP数组中的数据导出到excel中。同时支持php低版本和高版本

Use example: 使用示例

修改 项目中 composer.json 文件,如下: 重点是加上 requirerepositories

vi composer.json

{
    "name": "test",
    "type": "library",
    "minimum-stability": "dev",
    "require": {
        "jacena/php-excel-export": "dev-master"
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.org"
        },
        "jacena/php-excel-export": {
            "type": "git",
            "url": "https://github.com/jacena/php-excel-export.git"
        }
    }
}

必须加上 --ignore-platform-reqs 否则有些有些包装不上

  • 安装 install

    composer install --ignore-platform-reqs -vvv

  • 更新 update

    composer require --ignore-platform-reqs -vvv

调用示例 demo

vi test.php

<?php
namespace test;

require_once("vendor/autoload.php"); // 如果用的框架,肯定已经自动加载了。可以注释

use Jacena\PhpExcelMaker\PHPExcelMaker;

$keys = $title = [];

$data = [
    ['user_name'=>'jack', 'age'=>'20', 'sex'=>'1'],
    ['user_name'=>'hack', 'age'=>'30', 'sex'=>'2'],
    ['user_name'=>'jack', 'age'=>'22', 'sex'=>'1'],
    ['user_name'=>'jack', 'age'=>'23', 'sex'=>'2'],
    ['user_name'=>'jack', 'age'=>'32', 'sex'=>'2'],
    ['user_name'=>'jack', 'age'=>'40', 'sex'=>'2'],
    ['user_name'=>'jack', 'age'=>'60', 'sex'=>'1'],
];

$title = [
    'user_name' => '姓名',
    'age' => '年龄',
    'sex' => '性别',
];

$excel = new PHPExcelMaker();

if (PHP_SAPI == 'cli') {
    // var_dump($excel->getPHPVersion());exit;
    $excel->exportExcel($keys, $title, $data, 'xxx'); // 数组名和文件名一致
    exit;
}else {
    // var_dump($excel->getPHPVersion());exit;
    $excel->exportExcel($keys, $title, $data, 'xxxx', false); // 数组名和文件名一致
}

php-excel-export's People

Contributors

jacena avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.