chinahub/xls-writer

php xls library based on xlsWriter

v1.2.2 2022-04-14 09:29 UTC

This package is auto-updated.

Last update: 2024-09-14 14:40:03 UTC


README

php xls library based on xlsWriter, php-xlsWriter:https://github.com/viest/php-ext-xlswriter

Installation

Run the following command to install the latest applicable version of the package:

composer require chinahub/xls-writer

Env Required

  • xlswriter extention
pecl install xlswriter
# add extension = xlswriter.so to php.ini
  • recommend PHP > 7.4

Usage

Export

use Chinahub\XlsWriter\interfaces\ExportInterface;

class UserExport implements ExportInterface
{
    public function headers(): array
    {
        return ['id','name','email'];
    }

    public function data(): array
    {
        return [
            [1,'tom','test@qq.com'],
            [2,'lily','test@gmail.com'],
            [3,'lisa','test@163.com'],

        ];
    }
}

output path

use Chinahub\XlsWriter\Export;

$excel = new Export(new UserExport());
$excel->config = ['path' => '/www'];
$excel->fileName = 'user.xlsx';
$excel->output();

output download

use Chinahub\XlsWriter\Export;

$excel = new Export(new UserExport());
$excel->fileName = 'user.xlsx';
$excel->download();

Import

get all data from sheet

use Chinahub\XlsWriter\Import;

$excel = new Import('/www/user.xlsx');
$excel->getSheet();

get row from sheet

use Chinahub\XlsWriter\Import;

$excel = new Import('/www/user.xlsx');
$excel = $excel->instance();
while (($row = $excel->nextRow()) !== NULL) {
    var_dump($row);
}