PHPackages                             marshung/io - 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. marshung/io

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

marshung/io
===========

Import and Export Builder

1.0.0(2y ago)05.3k2[5 issues](https://github.com/marshung24/io/issues)[1 PRs](https://github.com/marshung24/io/pulls)MITPHP

Since Jun 10Pushed 2y agoCompare

[ Source](https://github.com/marshung24/io)[ Packagist](https://packagist.org/packages/marshung/io)[ Docs](https://github.com/marshung24/io)[ RSS](/packages/marshung-io/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (37)Used By (0)

匯出匯入模組
======

[](#匯出匯入模組)

[![Latest Stable Version](https://camo.githubusercontent.com/b6c082aeeefc9c99c5803ee8ea150d7581918f4d5969b9be752c91ac71ca25f7/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f696f2f762f737461626c65)](https://packagist.org/packages/marshung/io) [![Total Downloads](https://camo.githubusercontent.com/08e7797cc9f54523ef109a2734edf0c36d4d5c3c847a74c981e82739612bcbf5/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f696f2f646f776e6c6f616473)](https://packagist.org/packages/marshung/io) [![Latest Unstable Version](https://camo.githubusercontent.com/c7712507809b6628887a1193aeb4254cf9de0a9b86000e218da82d1622f41782/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f696f2f762f756e737461626c65)](https://packagist.org/packages/marshung/io) [![License](https://camo.githubusercontent.com/fce86689596567e9095b0a5548cd8fdd4f3f643b8b647c74db0786056c7d43f7/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f696f2f6c6963656e7365)](https://packagist.org/packages/marshung/io) [![composer.lock](https://camo.githubusercontent.com/531f7f28c109ef3eb65724aa785df664e96da190b2b0887360eb0c8817b4bbaa/68747470733a2f2f706f7365722e707567782e6f72672f6d61727368756e672f696f2f636f6d706f7365726c6f636b)](https://packagist.org/packages/marshung/io)

目錄
==

[](#目錄)

- [匯出匯入模組](#%E5%8C%AF%E5%87%BA%E5%8C%AF%E5%85%A5%E6%A8%A1%E7%B5%84)
- [目錄](#%E7%9B%AE%E9%8C%84)
- [說明](#%E8%AA%AA%E6%98%8E)
- [安裝](#%E5%AE%89%E8%A3%9D)
- [用法](#%E7%94%A8%E6%B3%95)
    - [有資料的結構定義物件](#%E6%9C%89%E8%B3%87%E6%96%99%E7%9A%84%E7%B5%90%E6%A7%8B%E5%AE%9A%E7%BE%A9%E7%89%A9%E4%BB%B6)
        - [匯出](#%E5%8C%AF%E5%87%BA)
        - [匯入](#%E5%8C%AF%E5%85%A5)
    - [空的結構定義物件](#%E7%A9%BA%E7%9A%84%E7%B5%90%E6%A7%8B%E5%AE%9A%E7%BE%A9%E7%89%A9%E4%BB%B6)
        - [匯出](#%E5%8C%AF%E5%87%BA-1)
        - [匯入](#%E5%8C%AF%E5%85%A5-1)
    - [手動處理-簡易模式](#%E6%89%8B%E5%8B%95%E8%99%95%E7%90%86-%E7%B0%A1%E6%98%93%E6%A8%A1%E5%BC%8F)
        - [匯出](#%E5%8C%AF%E5%87%BA-2)
        - [匯入](#%E5%8C%AF%E5%85%A5-2)
    - [手動處理-複雜模式](#%E6%89%8B%E5%8B%95%E8%99%95%E7%90%86-%E8%A4%87%E9%9B%9C%E6%A8%A1%E5%BC%8F)
        - [匯出](#%E5%8C%AF%E5%87%BA-3)
        - [匯入](#%E5%8C%AF%E5%85%A5-3)
- [樣式](#%E6%A8%A3%E5%BC%8F)
    - [可用清單](#%E5%8F%AF%E7%94%A8%E6%B8%85%E5%96%AE)
        - [顏色](#%E9%A1%8F%E8%89%B2)
        - [水平對齊](#%E6%B0%B4%E5%B9%B3%E5%B0%8D%E9%BD%8A)
        - [垂直對齊](#%E5%9E%82%E7%9B%B4%E5%B0%8D%E9%BD%8A)
        - [邊線](#%E9%82%8A%E7%B7%9A)
        - [儲存格格式](#%E5%84%B2%E5%AD%98%E6%A0%BC%E6%A0%BC%E5%BC%8F)
    - [設定方式](#%E8%A8%AD%E5%AE%9A%E6%96%B9%E5%BC%8F)
        - [設定檔](#%E8%A8%AD%E5%AE%9A%E6%AA%94)
        - [手動-複雜模式-樣式](#%E6%89%8B%E5%8B%95-%E8%A4%87%E9%9B%9C%E6%A8%A1%E5%BC%8F-%E6%A8%A3%E5%BC%8F)
        - [樣式後處理](#%E6%A8%A3%E5%BC%8F%E5%BE%8C%E8%99%95%E7%90%86)
            - [自動模式-樣式後處理](#%E8%87%AA%E5%8B%95%E6%A8%A1%E5%BC%8F-%E6%A8%A3%E5%BC%8F%E5%BE%8C%E8%99%95%E7%90%86)
            - [手動模式-樣式後處理](#%E6%89%8B%E5%8B%95%E6%A8%A1%E5%BC%8F-%E6%A8%A3%E5%BC%8F%E5%BE%8C%E8%99%95%E7%90%86)
- [多頁工作表](#%E5%A4%9A%E9%A0%81%E5%B7%A5%E4%BD%9C%E8%A1%A8)

說明
==

[](#說明)

為簡化匯出匯入使用法式，編寫此模組

安裝
==

[](#安裝)

```
$ composer require marshung/io
```

用法
==

[](#用法)

有資料的結構定義物件
----------

[](#有資料的結構定義物件)

需先定義好結構物件，匯出時，直接指定定義好的結構物件即可

> 結構物件參考： src/config/ComplexExampleConfig.php src/config/EmptyConfig.php src/config/SimpleExampleConfig.php

### 匯出

[](#匯出)

```
// 取得原始資料
$data = [
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Mars',
	            'id_no' => 'A234567890',
	            'birthday' => '2000-01-01',
	            'gender' => '1',
	        ],
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Jack',
	            'id_no' => 'A123456789',
	            'birthday' => '20001-01-01',
	            'gender' => '1',
	        ]
	    ];
```

```
// IO物件建構
$io = new \marshung\io\IO();

// 匯出處理 - 建構匯出資料 - 簡易模式結構定義物件-範本
$io->export($data, $config = 'SimpleExample', $builder = 'Excel', $style = 'Io');
```

```
// IO物件建構
$io = new \marshung\io\IO();

// 匯出處理 - 建構匯出資料 - 複雜模式結構定義物件-範本
$io->export($data, $config = 'ComplexExample', $builder = 'Excel', $style = 'Io');
```

```
// IO物件建構
$io = new \marshung\io\IO();

// 匯出處理 - 物件注入方式
$config = new \marshung\io\config\SimpleExampleConfig();
// 必要欄位設定 - 提供讀取資料時驗証用 - 有設定，且必要欄位有無資料者，跳出 - 因各版本excel對空列定義不同，可能編輯過列，就會產生沒有結尾的空列，導致在讀取excel時有讀不完狀況。
$config->setOption([
    'u_no'
], 'requiredField');
$builder = new \marshung\io\builder\ExcelBuilder();
$style = new \marshung\io\style\IoStyle();
// 欄位B凍結
$style->setFreeze('B');
$io->export($data, $config, $builder, $style);
```

> 需注意設置"必要欄位設定"，因各版本excel對空列定義不同，可能編輯過列，就會產生沒有結尾的空列，導致在讀取excel時有讀不完狀況。

### 匯入

[](#匯入)

```
// IO物件建構
$io = new \marshung\io\IO();
// 匯入處理 - 取得匯入資料
$data = $io->import($builder = 'Excel', $fileArgu = 'fileupload');
// 取得匯入config名子
$configName = $io->getConfig()->getOption('configName');
// 取得有異常有下拉選單內容
$mismatch = $io->getMismatch();
// $mismatch = $io->getConfig()->getMismatch();

echo 'Config Name = ' . $configName . "\n";
echo 'Data = ';
var_export($data);
echo "\n";
echo 'Exception content = ';
var_export($mismatch);
```

> 當有下拉選單的欄位，其輸入的內容不在下拉選單中，$data中的資料內容會是空字串，但原內容會記錄在$mismatch中

空的結構定義物件
--------

[](#空的結構定義物件)

如果不需要格式、樣式等設定，只需將資料陣列純輸出，可使用空結構定義

### 匯出

[](#匯出-1)

```
// 取得原始資料
$data = [
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Mars',
	            'id_no' => 'A234567890',
	            'birthday' => '2000-01-01',
	            'gender' => '1',
	        ],
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Jack',
	            'id_no' => 'A123456789',
	            'birthday' => '20001-01-01',
	            'gender' => '1',
	        ]
	    ];

// IO物件建構
$io = new \marshung\io\IO();
// 匯出處理 - 建構匯出資料 - 空的結構定義物件
$io->export($data, $config = 'Empty', $builder = 'Excel', $style = 'Io');
```

### 匯入

[](#匯入-1)

```
// IO物件建構
$io = new \marshung\io\IO();
// 匯入處理 - 取得匯入資料
$data = $io->import($builder = 'Excel', $fileArgu = 'fileupload');
// 取得匯入config名子
$configName = $io->getConfig()->getOption('configName');

echo 'Config Name = ' . $configName . "\n";
echo 'Data = ';
var_export($data);
```

手動處理-簡易模式
---------

[](#手動處理-簡易模式)

如果資料欄位為變動長度時，將無法定義完善的結構定義物件，此時可用手動模式

> 當然，此狀況可以定義好可預期的欄位結構，然後出現額外的欄位時，使用$config的getTitle(),getContent()取出資料並改寫，再利用setTitle(),setContent()回寫，並用setList()補充對映表資料即可

### 匯出

[](#匯出-2)

```
// 取得原始資料
$data = [
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Mars',
	            'id_no' => 'A234567890',
	            'birthday' => '2000-01-01',
	            'gender' => '1',
	        ],
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Jack',
	            'id_no' => 'A123456789',
	            'birthday' => '20001-01-01',
	            'gender' => '1',
	        ]
	    ];

// 結構定義-簡易模式
$defined = array(
    'u_no' => '員工編號',
    'c_name' => '姓名',
    'id_no' => '身分證字號',
    'birthday' => '出生年月日',
    'gender' => '性別'
);

// IO物件建構
$io = new \marshung\io\IO();

// 手動建構相關物件
$io->setConfig()
    ->setBuilder()
    ->setStyle();

// 載入外部定義
$conf = $io->getConfig()
    ->setTitle($defined)
    ->setContent($defined);

// 建構外部對映表
$listMap = array(
    'gender' => array(
        array(
            'value' => '1',
            'text' => '男'
        ),
        array(
            'value' => '0',
            'text' => '女'
        )
    )
);

// 載入外部對映表
$conf->setList($listMap);

// 必要欄位設定 - 提供讀取資料時驗証用 - 有設定，且必要欄位有無資料者，跳出 - 因各版本excel對空列定義不同，可能編輯過列，就會產生沒有結尾的空列，導致在讀取excel時有讀不完狀況。
$conf->setOption([
    'u_no'
], 'requiredField');

// 匯出處理 - 建構匯出資料 - 手動處理
$io->setData($data)->exportBuilder();
```

### 匯入

[](#匯入-2)

```
// IO物件建構
$io = new \marshung\io\IO();
// 匯入處理 - 取得匯入資料
$data = $io->import($builder = 'Excel', $fileArgu = 'fileupload');
// 取得匯入config名子
$configName = $io->getConfig()->getOption('configName');

echo 'Config Name = ' . $configName . "\n";
echo 'Data = ';
var_export($data);
```

手動處理-複雜模式
---------

[](#手動處理-複雜模式)

如果資料欄位為變動長度時，將無法定義完善的結構定義物件，此時可用手動模式

> 當然，此狀況可以定義好可預期的欄位結構，然後出現額外的欄位時，使用$config的getTitle(),getContent()取出資料並改寫，再利用setTitle(),setContent()回寫，並用setList()補充對映表資料即可

### 匯出

[](#匯出-3)

```
// 取得原始資料
$data = [
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Mars',
	            'id_no' => 'A234567890',
	            'birthday' => '2000-01-01',
	            'gender' => '1',
	        ],
	        [
	            'u_no' => 'A001',
	            'c_name' => 'Jack',
	            'id_no' => 'A123456789',
	            'birthday' => '20001-01-01',
	            'gender' => '1',
	        ]
	    ];

// 結構定義-複雜模式
// 標題1
$title1 = array(
    'config' => array(
        'type' => 'title',
        'name' => 'title1',
        'style' => array(
            'font-size' => '16'
        ),
        'class' => ''
    ),
    'defined' => array(
        't1' => array(
            'key' => 't1',
            'value' => '帳號',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't2' => array(
            'key' => 't2',
            'value' => '姓名',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't3' => array(
            'key' => 't3',
            'value' => '身分證字號',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't4' => array(
            'key' => 't4',
            'value' => '生日',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't5' => array(
            'key' => 't4',
            'value' => '性別',
            'col' => '2',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        )
    )
);

// 標題2
$title2 = array(
    'config' => array(
        'type' => 'title',
        'name' => 'example',
        'style' => array(),
        'class' => 'example'
    ),
    'defined' => array(
        't1' => array(
            'key' => 't1',
            'value' => 'A001',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't2' => array(
            'key' => 't2',
            'value' => '派大星',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't3' => array(
            'key' => 't3',
            'value' => 'ET9000001',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't4' => array(
            'key' => 't4',
            'value' => '2000-01-01',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        't5' => array(
            'key' => 't4',
            'value' => '男',
            'col' => '2',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        )
    )
);

// 內容
$content = array(
    'config' => array(
        'type' => 'content',
        'name' => 'content',
        'style' => array(),
        'class' => ''
    ),
    'defined' => array(
        'u_no' => array(
            'key' => 'u_no',
            'value' => '帳號',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        'c_name' => array(
            'key' => 'c_name',
            'value' => '姓名',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        'id_no' => array(
            'key' => 'id_no',
            'value' => '身分證字號',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        'birthday' => array(
            'key' => 'birthday',
            'value' => '生日',
            'col' => '1',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
        'gender' => array(
            'key' => 'gender',
            'value' => '性別',
            'col' => '2',
            'row' => '1',
            'style' => array(),
            'class' => '',
            'default' => '1',
            'list' => ''
        )
    )
);

// IO物件建構
$io = new \marshung\io\IO();

// 手動建構相關物件
$io->setConfig()
    ->setBuilder()
    ->setStyle();

// 載入外部定義
$conf = $io->getConfig()
    ->setTitle($title1)
    ->setTitle($title2)
    ->setContent($content);

// 建構外部對映表
$listMap = array(
    'gender' => array(
        array(
            'value' => '1',
            'text' => '男'
        ),
        array(
            'value' => '0',
            'text' => '女'
        )
    )
);

// 載入外部對映表
$conf->setList($listMap);

// 必要欄位設定 - 提供讀取資料時驗証用 - 有設定，且必要欄位有無資料者，跳出 - 因各版本excel對空列定義不同，可能編輯過列，就會產生沒有結尾的空列，導致在讀取excel時有讀不完狀況。
$conf->setOption([
    'u_no'
], 'requiredField');

// 匯出處理 - 建構匯出資料 - 手動處理
$io->setData($data)->exportBuilder();
```

### 匯入

[](#匯入-3)

```
// IO物件建構
$io = new \marshung\io\IO();
// 匯入處理 - 取得匯入資料
$data = $io->import($builder = 'Excel', $fileArgu = 'fileupload');
// 取得匯入config名子
$configName = $io->getConfig()->getOption('configName');
// 取得有異常有下拉選單內容
$mismatch = $io->getMismatch();
// $mismatch = $io->getConfig()->getMismatch();

echo 'Config Name = ' . $configName . "\n";
echo 'Data = ';
var_export($data);
echo "\n";
echo 'Exception content = ';
var_export($mismatch);
```

> 當有下拉選單的欄位，其輸入的內容不在下拉選單中，$data中的資料內容會是空字串，但原內容會記錄在$mismatch中

樣式
==

[](#樣式)

可用清單
----

[](#可用清單)

### 顏色

[](#顏色)

代碼色碼顏色blackFF000000黑色blueFF0000FF藍色darkblueFF000080深藍darkgreenFF008000深綠darkredFF800000深紅darkyellowFF808000深黃greenFF00FF00綠redFFFF0000紅whiteFFFFFFFF白yellowFFFFFF00黃### 水平對齊

[](#水平對齊)

代碼方式center置中centercontinuousgeneral一般justify左右貼齊left靠左right靠右### 垂直對齊

[](#垂直對齊)

代碼方式bottom置底center置中middle置中justifytop置頂### 邊線

[](#邊線)

代碼說明dashdotdashdotdotdasheddotteddoublehairmediummediumdashdotmediumdashdotdotmediumdashednoneslantdashdotthickthin### 儲存格格式

[](#儲存格格式)

代碼說明備註general通用格式txt文字text文字string文字number數字number\_00數字(小數二位)date日期可配合config的$\_options\['dateFormat'\]欄位定義日期格式time時間datetime日期+時間設定方式
----

[](#設定方式)

### 設定檔

[](#設定檔)

- 自定樣式檔

```
class MyStyle extends marshung\io\style\IoStyle
{
    public function __construct()
    {
        parent::__construct();
        // 初始化 - 預設樣式
        $this->run();
    }

     /**
     * 初始化 - 預設樣式
     * 'width' => 20.71,//儲存格欄寬
     * 'height' => -1,//儲存格欄高(-1為自動高度)
     * 'wraptext' => true,//儲存格自動換行
     * 'font-name' => '微軟正黑體',//字體字型
     * 'font-size' => 11,//字體大小
     * 'font-bold' => false,//字體粗體
     * 'font-underline' => false,//字體底線
     * 'font-color' => 'black',//字體顏色
     * 'align-horizontal' => 'left',//水平對齊
     * 'align-vertical' => 'center',//垂直對齊
     * 'border-all-style' => 'thin',//欄線樣式-全部
     * 'border-all-color' => 'FF9F9FA0',//欄線顏色-全部
     * 'border-top-style' => 'thin',//上欄線樣式
     * 'border-left-style' => 'thin',//左欄線樣式
     * 'border-right-style' => 'thin',//右欄線樣式
     * 'border-bottom-style' => 'thin',//下欄線樣式
     * 'border-outline-style' => 'thin',//外圈線樣式
     * 'border-inside-style' => 'thin',//內部線樣式
     * 'border-top-color' => 'FFDADCDD',//上欄線顏色
     * 'border-left-color' => 'FFDADCDD',//左欄線顏色
     * 'border-right-color' => 'FFDADCDD',//右欄線顏色
     * 'border-bottom-color' => 'FFDADCDD',//下欄線顏色
     * 'border-outline-color' => 'FFDADCDD',//外圈欄線顏色
     * 'border-inside-color' => 'FFDADCDD',//內部欄線顏色
     * 'background-color' => 'white'//儲存格背景顏色
     * 'row-odd-background-color' => 'F7F7F7',//內容奇數列背景顏色
     * 'row-even-background-color' => 'white'//內容偶數列背景顏色
     */
    protected function initDefault()
    {
        // 自定樣式集
        $this->_classMap['mystyle'] = array(
            'width' => 20.71, // 儲存格欄寬
            'height' => - 1, // 儲存格欄高(-1為自動高度)
            'format' => 'text', // 儲存格格式-文字
            'wraptext' => true, // 儲存格自動換行
            'font-name' => '微軟正黑體', // 字體字型
            'font-size' => 11, // 字體大小
            'font-color' => 'black', // 字體顏色
            'align-vertical' => 'center', // 垂直對齊
            'border-all-style' => 'thin', // 欄線樣式-全部
            'border-all-color' => 'FF9F9FA0' // 欄線顏色-全部
        );
    }
}
```

- 設定結構構設定檔 config (節錄) 如標題要用自定樣式集

```
$this->_title[] = array(
    'config' => array(
        'type' => 'title',
        'name' => 'title1',
        // 自定樣式
        'style' => array(
            'font-size' => '16'
        ),
        // 樣式集名稱
        'class' => 'mystyle'
    ),
    'defined' => array(
        't1' => array(
            'key' => 't1',
            'value' => '日期',
            'col' => '1',
            'row' => '1',
            // 自定樣式
            'style' => array('format' => 'date'),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
);
```

### 手動-複雜模式-樣式

[](#手動-複雜模式-樣式)

```
$style = new \marshung\io\style\IoStyle();
$style->setClass(array(
            'width' => 20.71, // 儲存格欄寬
            'height' => - 1, // 儲存格欄高(-1為自動高度)
            'format' => 'text', // 儲存格格式-文字
            'wraptext' => true, // 儲存格自動換行
            'font-name' => '微軟正黑體', // 字體字型
            'font-size' => 11, // 字體大小
            'font-color' => 'black', // 字體顏色
            'align-vertical' => 'center', // 垂直對齊
            'border-all-style' => 'thin', // 欄線樣式-全部
            'border-all-color' => 'FF9F9FA0' // 欄線顏色-全部
        ), 'mystyle');

// 標題1
$title1 = array(
    'config' => array(
        'type' => 'title',
        'name' => 'title1',
        // 自定樣式
        'style' => array(
            'font-size' => '16'
        ),
        // 樣式集名稱
        'class' => 'mystyle'
    ),
    'defined' => array(
        't1' => array(
            'key' => 't1',
            'value' => '日期',
            'col' => '1',
            'row' => '1',
            // 自定樣式
            'style' => array('format' => 'date'),
            'class' => '',
            'default' => '',
            'list' => ''
        ),
);

// IO物件建構
$io = new \marshung\io\IO();

// 手動建構相關物件
$io->setConfig()
    ->setBuilder()
    ->setStyle();

// 載入外部定義
$conf = $io->getConfig()
    ->setTitle($title1)
    ->setTitle($title2)
    ->setContent($content);

// 略，參照： 手動 - 複雜模式
```

### 樣式後處理

[](#樣式後處理)

為因應過於特殊的樣式設定，開放樣式後處理

#### 自動模式-樣式後處理

[](#自動模式-樣式後處理)

```
// 取得原始資料
$data = getData('3');

// IO物件建構
$io = new \marshung\io\IO();

// 匯出處理 - 物件注入方式
$config = new \marshung\io\config\ComplexExampleConfig();
$builder = new \marshung\io\builder\ExcelBuilder();
$style = new \marshung\io\style\IoStyle();

// Output format: file, phpSpreadsheet(src/object/sheet/spreadsheet/phpspreadsheet)
$builder->setOption('object', 'outputFormat');

// 建構輸出物件
$spreadsheet = $io->export($data, $config, $builder, $style);

// 自定樣式 - style後處理
$titleStyle = ['background-color' => 'FF0094D8'];
$titleRange = 'A4:C4';
\marshung\io\builder\ExcelStyleBuilder::setExcelRangeStyle($titleStyle, $spreadsheet, $titleRange);

// 重新輸出
$builder->output('my_file_name', 'file');
```

#### 手動模式-樣式後處理

[](#手動模式-樣式後處理)

```
// 取得原始資料
$data = getData('7');

// 結構定義-簡易模式
$defined = array('....');

// IO物件建構
$io = new \marshung\io\IO();

// 手動建構相關物件
$io->setConfig()->setBuilder()->setStyle();

// 載入外部定義
$conf = $io->getConfig()->setTitle($defined)->setContent($defined);

// 建構外部對映表
$listMap = array('...');

// 取得建構物件
$builder = $io->getBuilder();
// Output format: file, phpSpreadsheet(src/object/sheet/spreadsheet/phpspreadsheet)
$builder->setOption('object', 'outputFormat');

// 載入外部對映表
$conf->setList($listMap);

// 匯出處理 - 建構匯出資料
$spreadsheet = $io->setData($data)->exportBuilder();

// 自定樣式 - style後處理
$titleStyle = ['background-color' => 'FF0094D8'];
$titleRange = 'B4:D4';
\marshung\io\builder\ExcelStyleBuilder::setExcelRangeStyle($titleStyle, $spreadsheet, $titleRange);

// 重新輸出
$builder->output('export7', 'file');
```

多頁工作表
=====

[](#多頁工作表)

```
// 取得原始資料
$data = getData('10');
$deptData = getDeptData('10');

// 匯出處理 - 物件注入方式
$config1 = new \marshung\io\config\ComplexExampleConfig();
$config2 = new \marshung\io\config\ComplexExampleDeptConfig();
$builder = new \marshung\io\builder\ExcelBuilder();
$style = new \marshung\io\style\IoStyle();

// 欄位B凍結
$style->setFreeze('B');

// 手動建構相關物件
$spreadsheet = $builder->setData($data)
    ->setConfig($config1)
    ->setStyle($style)
    ->build()
    ->setConfig($config2)
    ->setData($deptData)
    ->build()
    ->output('export-10', 'file');
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 91% 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 ~62 days

Recently: every ~335 days

Total

30

Last Release

1077d ago

Major Versions

0.9.11 → 1.0.02023-06-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34496839?v=4)[MarsHung](/maintainers/marshung24)[@marshung24](https://github.com/marshung24)

---

Top Contributors

[![marshung24](https://avatars.githubusercontent.com/u/34496839?v=4)](https://github.com/marshung24 "marshung24 (61 commits)")[![gunter1020](https://avatars.githubusercontent.com/u/15287859?v=4)](https://github.com/gunter1020 "gunter1020 (6 commits)")

### Embed Badge

![Health badge](/badges/marshung-io/health.svg)

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

PHPackages © 2026

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