vielhuber/excelhelper

一个超简单的PHP Excel包装器。

1.2.2 2023-01-21 00:08 UTC

This package is auto-updated.

Last update: 2024-09-21 04:02:37 UTC


README

build status

📗 excelhelper 📗

excelhelper是一个Excel辅助工具。

借助它,您可以用非常简单、适合Web开发的方式在PHP中编写和读取xlsx/xls/csv文件。它还处理了大数和其他怪异的问题。

安装

使用composer一次性安装

composer require vielhuber/excelhelper

然后将以下内容添加到您的文件中

require __DIR__ . '/vendor/autoload.php';
use vielhuber\excelhelper\excelhelper;

使用方法

读取

$array = excelhelper::read([
    'file' => 'file.xlsx',
    'first_line' => true, // true|false
    'format_cells' => false, // false|true
    'all_sheets' => false, // false|true
    'friendly_keys' => false // false|true
]);

写入

excelhelper::write([
    'file' => 'file.xlsx', // can write xlsx, xls and csv; if null, a filename is suggested
    'engine' => 'phpspreadsheet',
    'output' => 'save', // save|download
    'style_header' => true, // true|false
    'autosize_columns' => true, // true|false
    'auto_borders' => true, // true|false
    'remove_empty_cols' => false, // true|false
    'data' => [
        ['a1', 'b1', 'c1'],
        ['a2', 'b2', 'c2'],
        [
            [
                'value' => 'a3',
                'background-color' => '#ff0000',
                'color' => '#ffffff',
                'font-weight' => 'bold',
                'border' => '1px solid #000',
                'text-align' => 'center'
            ],
            [
                'value' => 'b3',
                'background-color' => '#ff0000',
                'color' => '#ffffff',
                'font-weight' => 'bold',
                'border' => '1px solid #000',
                'text-align' => 'left'
            ],
            [
                'value' => 'c3',
                'background-color' => '#ff0000',
                'color' => '#ffffff',
                'font-weight' => 'bold',
                'border' => '1px solid #000',
                'text-align' => 'right'
            ]
        ]
    ]
]);
excelhelper::write([
    'file' => 'file.xlsx',
    'engine' => 'phpspreadsheet',
    'output' => 'save',
    'data' => [
        'Sheet 1' => [['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']],
        'Sheet 2' => [['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']],
        'Sheet 3' => [['a1', 'b1', 'c1'], ['a2', 'b2', 'c2']]
    ]
]);