shuchkin/simplexls 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

shuchkin/simplexls

Composer 安装命令:

composer require shuchkin/simplexls

包简介

Parse and retrieve data from old format Excel XLS files. MS Excel 97 workbooks PHP reader.

README 文档

README

Parse and retrieve data from old Excel .XLS files. MS Excel 97-2003 workbooks PHP reader. PHP BIFF reader. No additional extensions needed (internal olereader).
Modern .XLSX php reader here.

Hey, bro, please ★ the package for my motivation :) and donate for more motivation!

Sergey Shuchkin sergey.shuchkin@gmail.com 2016-2025

Basic Usage

if ( $xls = SimpleXLS::parseFile('book.xls') ) {
	print_r( $xls->rows() );
	// echo $xls->toHTML();	
} else {
	echo SimpleXLS::parseError();
}
Array
(
    [0] => Array
        (
            [0] => ISBN
            [1] => title
            [2] => author
            [3] => publisher
            [4] => ctry
        )

    [1] => Array
        (
            [0] => 618260307
            [1] => The Hobbit
            [2] => J. R. R. Tolkien
            [3] => Houghton Mifflin
            [4] => USA
        )

)

Installation

composer require shuchkin/simplexls

or download class here

PHP 5.5-8.4

Basic methods

// open
SimpleXLS::parse( $filename, $is_data = false, $debug = false ): SimpleXLS (or false)
SimpleXLS::parseFile( $filename, $debug = false ): SimpleXLS (or false)
SimpleXLS::parseData( $data, $debug = false ): SimpleXLS (or false)
SimpleXLS:parseError(): string
// simple
$xls->rows($worksheetIndex = 0, $limit = 0): array
$xls->readRows($worksheetIndex = 0, $limit = 0): Generator - helps read huge xlsx
$xls->toHTML($worksheetIndex = 0, $limit = 0): string
// extended
$xls->rowsEx($worksheetIndex = 0, $limit = 0): array, values + meta
// meta
$xls->sheetNames():array
$xls->sheetName($worksheetIndex):string

Examples

XLS to html table

echo SimpleXLS::parse('book.xls')->toHTML();

or

if ( $xls = SimpleXLS::parse('book.xls') ) {
	echo '<table border="1" cellpadding="3" style="border-collapse: collapse">';
	foreach( $xls->rows() as $r ) {
		echo '<tr><td>'.implode('</td><td>', $r ).'</td></tr>';
	}
	echo '</table>';
} else {
	echo SimpleXLS::parseError();
}

Sheet names

if ( $xls = SimpleXLS::parseFile('book.xls') ) {
  print_r( $xls->sheetNames() );
  print_r( $xls->sheetName( $xls->activeSheet ) );
}
Array
(
    [0] => Sheet 1
    [1] => Sheet 2
    [2] => Sheet 3
)
Sheet 2

Sheets info

if ( $xls = SimpleXLS::parseFile('book.xls') ) {
  print_r( $xls->boundsheets ); 
}
Array
(
    [0] => Array
        (
            [name] => Sheet 1
            [offset] => 15870
            [hidden] => 
            [active] => 
        )

    [1] => Array
        (
            [name] => Sheet 2
            [offset] => 16308
            [hidden] => 1
            [active] => 1
        )

    [2] => Array
        (
            [name] => Sheet 3 
            [offset] => 16746
            [hidden] => 
            [active] => 
        )
)

Classic OOP style

$xls = new SimpleXLS('books.xls');
if ($xls->success()) {
	print_r( $xls->rows() );
} else {
	echo 'xls error: '.$xls->error();
}

Debug

ini_set('error_reporting', E_ALL );
ini_set('display_errors', 1 );

//header('Content-Type: text/html; charset=utf-8');

$xls = SimpleXLSX::parse('books.xls', false, true );
print_r( $xls->rows() );
print_r( $xls->sheets );

History

1.0.0 (2025-03-04) 7 years, 400k downloads, we need release
0.11.1 (2025-02-14) PHP 5.5-8.4 support, fixed datetime cells thx tomu4
0.10.5 (2024-09-17) readRows() returns Generator, thx livingroot
0.10.4 (2023-11-13) more compatible with PHP 8.1
0.10.3 (2022-10-04) namespaced examples
0.10.2 (2022-09-01) fixed percent values
0.10.1 (2022-04-04) PHP 7.1+, PHP 8.0+
0.9.15 (2021-12-01)
  added $xls->sheetNames(), \$xls->sheetName( $index ), $xls->activeSheet
  added $limit in $xls->rows( $sheetIndex, $limit = 0 )
  more examples in README
0.9.14 (2021-11-04) Detect datetime format
0.9.13 (2021-09-21) Fixed éàù... in sheet names, added flag hidden in $xls->boundsheets info
0.9.12 (2021-09-20) Fixed éàù...
0.9.11 (2021-09-02) Added Rows with header values as keys example
0.9.10 (2021-05-19) SimpleXLSX to SimpleXLS in example
0.9.9 (2021-03-04) Added $xls->toHTML()
0.9.8 (2021-03-04) Fixed skipping first row & col, fixed datetime format in unicode 0.9.7 (2021-02-26) Added ::parseFile(), ::parseData()
0.9.6 (2020-12-01) Fixed README
0.9.5 (2020-01-16) Fixed negative number values and datetime values
0.9.4 (2019-03-14) Added git Tag for prevent composer warning
0.9.3 (2019-02-19) Fixed datetime detection
0.9.2 (2018-11-15) GitHub release, composer

shuchkin/simplexls 适用场景与选型建议

shuchkin/simplexls 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 655.61k 次下载、GitHub Stars 达 211, 最近一次更新时间为 2018 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「excel」 「xls」 「parser」 「backend」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 655.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 212
  • 点击次数: 28
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 211
  • Watchers: 8
  • Forks: 82
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-14