定制 sonichaos360/phpsimplespreadsheet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sonichaos360/phpsimplespreadsheet

Composer 安装命令:

composer require sonichaos360/phpsimplespreadsheet

包简介

Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.

README 文档

README

PHPSimpleSpreadsheet

Simple but powerful PHP library to generate on-disk XLSX spreadsheets focused in low memory usage.

Usage

Basic Spreadsheet

require('../../src/PHPSimpleSpreadsheet.php');

$xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

$xls
//Sheet Name
->setName('test')
//Author Name
->setAuthor('Luciano Vergara')
//Set Columns range
->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
//Set Columns width
->setColumnsWidth(['25', '35', '35', '35', '35', '35', '35', '35', '35']);

//Start Sheet
$xls->startSheet();

//SetData
$count = 1;

//Set header row, style bold
$xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA'], "bold");

//Increment row count
$count++;

//Add data using insertRow and pass range ordered array values
while ($count <= 10) {
    //Set row data

    if($count == 5) {
        $xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA'], "italic");
    } else {
        $xls->insertRow(['A DATA', 'B DATA', 'C DATA', 'D DATA', 'E DATA', 'F DATA', 'G DATA', 'H DATA', 'I DATA']);    
    }
    
    //Show row number on console
    $count++;
}

//Close sheet data
$xls->endSheet();

/*
* Save file (ZIP TO XLSX) if there are so many regs ON your sheet and PHP can't zip the files
* you can use any other program on your terminal, zip the files and rename the resultant file as NAME.xlsx
* That's all
*/
if ($xls->doXmlx('test.xlsx')) {
    echo "File generated successfully. <a href=\"test.xlsx\">OPEN FILE<a>";
} else {
    throw new Exception('There was a problem generating the Spreadsheet.');
}

Advanced Paginated Spreadsheet (Lots of rows)

require('../../src/PHPSimpleSpreadsheet.php');

/**
 * Create object
 */
$xls = new Sonichaos360\PHPSimpleSpreadsheet\PHPSimpleSpreadsheet();

/**
 * Define number of elements per page
 */
$elements = 100;

/**
 * Defile total items to export
 */
$total_elements = 500;

/**
 * Get the pointer paremeter,
 * just a counter to know the current page
 * If it is NULL then we know this is the first page
 */
$pointer = (!isset($_GET["pointer"]) ? $elements : $_GET["pointer"]);

/**
 * If this is the first page
 * then we should start the spreadsheet
 * Else we just continue the current spreadsheet
 */
 if ($pointer == $elements) {
     /**
      * Start class
      */
     $xls
    ->setName('test')
    ->setAuthor('Luciano Vergara')
    ->setRange(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'])
    ->startSheet();
 } else {
     /**
     * You shound use the sheet name as parameter to continue,
     * in this case "test" is the name we defined before
     */
     $xls->continueSheet("test");
 }

//SetData
$count = 1;

//Set header row, style bold
if($pointer == $elements)
{
    $xls->insertRow(['A '.$pointer.' DATA', 'B '.$pointer.' DATA', 'C '.$pointer.' DATA', 'D '.$pointer.' DATA', 'E '.$pointer.' DATA', 'F '.$pointer.' DATA', 'G '.$pointer.' DATA', 'H '.$pointer.' DATA', 'I '.$pointer.' DATA'], "bold");
}

//Increment row count
$count++;

//Add data using insertRow and pass range ordered array values
while ($count <= $elements) {
    /**
     * Here you can do your querys or something like that to
     * obtain the data using LIMIT clauses or similar indicating
     * the $pointer variable as LIMIT and set data to the ROW
     */

    //Set row data
    $xls->insertRow(['A '.$pointer.' DATA', 'B '.$pointer.' DATA', 'C '.$pointer.' DATA', 'D '.$pointer.' DATA', 'E '.$pointer.' DATA', 'F '.$pointer.' DATA', 'G '.$pointer.' DATA', 'H '.$pointer.' DATA', 'I '.$pointer.' DATA']);

    //Show row number on console
    $count++;
}

/**
 * If we can not reach the pag limit then pause sheet
 * Else we should just end the sheet
 */
if ($pointer < $total_elements) {
    $xls->pauseSheet(); ?>
    <strong><?php echo $pointer; ?> OUT OF <?php echo $total_elements; ?> ELEMENTS PROCESSED...</strong>
    <script>
        /**
        * In JS just reload page and increase counter
        */
        setTimeout(function(){
            window.location.href = 'paginated.php?pointer=<?php echo($pointer+$elements); ?>';
        }, 3000);
    </script>
    <?php
} else {
        /**
        * End Sheet
        */
        $xls->endSheet();

        /*
        * Save file (ZIP TO XLSX) if there are so many regs ON your sheet and PHP can't zip the files
        * you can use any other program on your terminal, zip the files and rename the resultant file as NAME.xlsx
        * That's all
        */
        if ($xls->doXmlx('test.xlsx')) {
            echo "File generated successfully. <a href=\"test.xlsx\">OPEN FILE<a>";
        } else {
            throw new Exception('There was a problem generating the Spreadsheet.');
        }
}

Licence

The Software is provided "as is", without warranty of any kind. Please refer to the license file.

sonichaos360/phpsimplespreadsheet 适用场景与选型建议

sonichaos360/phpsimplespreadsheet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sonichaos360/phpsimplespreadsheet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sonichaos360/phpsimplespreadsheet 我们能提供哪些服务?
定制开发 / 二次开发

基于 sonichaos360/phpsimplespreadsheet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2021-08-08