PHPackages                             shijunjun/exim - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. shijunjun/exim

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shijunjun/exim
==============

导入导出

v0.0.11(5y ago)31044MITPHPPHP &gt;=7.0.0

Since Sep 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/shijunjun/exim)[ Packagist](https://packagist.org/packages/shijunjun/exim)[ RSS](/packages/shijunjun-exim/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (2)Versions (12)Used By (0)

exim
====

[](#exim)

基于[xlswriter](https://github.com/viest/php-ext-excel-export)扩展的导出导入,目前只支持xlsx,csv,xls文件的导入和导出

### xlswriter安装

[](#xlswriter安装)

```
git clone https://github.com/viest/php-ext-excel-export
cd php-ext-excel-export
git submodule update --init
`which phpize` && ./configure --with-php-config=`which php-config` --enable-reader && make && make install

# 编辑php.ini
[xlswriter]
extension=xlswriter.so
```

### 用法

[](#用法)

```
composer require shijunjun/exim
```

### export(导出)

[](#export导出)

```
$callback = function($item){
	return $item;
};
$export = new \shijunjun\exim\Export($callback);

$config = [
    // 导出的文件存放位置
    'path' => __DIR__.'/xls',
    // 非必需,导出的文件名
    'filename'=> date('YmdHis'),
    // 设置表格sheet名称,默认sheet1
    'sheetname'=> 'sheet1',
    // 导出的字段
    'columns'=>[
        'id'=>'ID',
        'band_id'=>'品牌ID',
        'sku_uuid'=>'商品规格ID',
        'category_id'=>'后端分类ID',
        'create_at'=>'添加时间',
        'goods_sku_code'=>'SKU编码',
        'goods_uuid'=>'商品ID',
        'img_url'=>'封面图片',
        'invoice_ord'=>'普通发票', //  0 不支持 1 支持
        'invoice_spe'=>'增值税专票',// 0 不支持 1 支持
        'invoice_spe_ord'=>'增值税普票', //  0 不支持 1 支持
        'is_default'=>'是否默认展示', //  1-是 2-否
        'limit'=>'最大购买量',
        'price_in'=>'进货价',
        'sku_name'=>'商品规格名称',
        'spec_name'=>'属性值拼接(,拼接)',
        'special_code'=>'商品69码',
        'status'=>'状态', // 1-正常 2-禁用 3-伪删除
        'supplier_uuid'=>'供应商ID',
        'update_at'=>'更新时间',
        'volume'=>'体积',
        'weight'=>'重量',
        'zone'=>'专区', //   1会员专区 2购物券专区 3大众好货专区
    ],
    // MySQL链接信息
    'mysql'=>[
    		// 优先读取dsn,如果dsn不存在那么就查找host,dbname,port
    		'dsn'=>'mysql:host=localhost;dbname=test;port=3306'
    		'host'=>"192.168.56.190",'user'=>"root",'password'=>"MySQL123#","dbname"=>"tests"
    	],
    // 执行sql
    'sql' => "select
                *,
                (case `invoice_ord` when 0 then '不支持' else '支持' end) as `invoice_ord`,
                (case `invoice_spe` when 0 then '不支持' else '支持' end) as `invoice_spe`,
                (case `invoice_spe_ord` when 0 then '不支持' else '支持' end) as `invoice_spe_ord`,
                (case `status` when 1 then '正常' when 2 then '禁用'  else '删除' end) as `status`,
                (case `zone` when 1 then '会员专区' when 2 then '购物券专区'  else '大众好货专区' end) as `zone`
              from goods_sku",
];

$out = $export->config($config)->setLimit(3000)->setMaxLine(100000)->openZip()->output();

// 等价于

$export->config($config);		// 设置导出数据基本必需参数
$export->setLimit(3000);		// 设置每次查询条数
$export->setMaxLine(100000);		// 如果设置此项则会对导出文件进行分割,默认为0表示不分割,大于0表示分割并且每个excel文件的最大行数
$export->openZip();			// 开启压缩 boolean
$out = $export->output();		// 输出文件

// ----------------------------------------------------------
var_export($out);
array (
  // excel文件列表
  'files' => array (),
  // 压缩后的文件全路径名称
  'zip_name' => '/data/www/io/app/xls/20190924191710.zip',
  // 执行时间
  'time' => '262.03791904449秒',
  // 占用内存
  'memory' => '0.09M',
)
```

### import(导入)

[](#import导入)

```
$read = (new \shijunjun\exim\Read([
    'file'=> $file, // 要导入的文件
    'size'=>1000, // 每次获取读取行数
    'cloumns'=>[
        'A'=>'id' ,// 'ID',
        'B'=>'band_id' ,// '品牌ID',
        'C'=>'sku_uuid' ,// '商品规格ID',
        'D'=>'category_id' ,// '后端分类ID',
        'E'=>'create_at' ,// '添加时间',
        'F'=>'goods_sku_code' ,// 'SKU编码',
        'G'=>'goods_uuid' ,// '商品ID',
        'H'=>'img_url' ,// '封面图片',
        'I'=>'invoice_ord' ,// '普通发票',
        'J'=>'invoice_spe' ,// '增值税专票',
        'K'=>'invoice_spe_ord' ,// '增值税普票',
        'L'=>'is_default' ,// '是否默认展示',
        'M'=>'limit' ,// '最大购买量',
        'N'=>'price_in' ,// '进货价',
        'O'=>'sku_name' ,// '商品规格名称',
        'P'=>'spec_name' ,// '属性值拼接(,拼接)',
        'Q'=>'special_code' ,// '商品69码',
        'R'=>'status' ,// '状态'
        'S'=>'supplier_uuid' ,// '供应商ID',
        'T'=>'update_at' ,// '更新时间',
        'U'=>'volume' ,// '体积',
        'V'=>'weight' ,// '重量',
        'W'=>'zone' ,// '专区',
    ],
]));

// 文件是否有标题如果有标题那么请设置true(默认值,可以省略),否则为false
$read->isSetTitle(false);

// 遍历数据
foreach ($read->list() as $item)
{
    var_export( $item );
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~75 days

Total

11

Last Release

2112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/28e2e837a983a766e0eb9293408948e8caa9bc07d9883e3e39c4585a4fd89362?d=identicon)[shijunjun](/maintainers/shijunjun)

---

Top Contributors

[![shijunjun](https://avatars.githubusercontent.com/u/7324365?v=4)](https://github.com/shijunjun "shijunjun (31 commits)")

### Embed Badge

![Health badge](/badges/shijunjun-exim/health.svg)

```
[![Health](https://phpackages.com/badges/shijunjun-exim/health.svg)](https://phpackages.com/packages/shijunjun-exim)
```

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[in2code/powermail

Powermail is a well-known, editor-friendly, powerful and easy to use mailform extension for TYPO3 with a lots of features

982.5M38](/packages/in2code-powermail)[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.3k](/packages/blair2004-nexopos)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

52664.9k12](/packages/solspace-craft-freeform)[pimcore/data-importer

Adds a comprehensive import functionality to Pimcore Datahub

44763.4k2](/packages/pimcore-data-importer)[portphp/spreadsheet

PhpSpreadsheet reader and writer for Port

14796.4k4](/packages/portphp-spreadsheet)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
