wwtg99/structure-files

0.2.0 2016-07-28 10:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:14:41 UTC


README

一个用于部分结构文件的通用接口,以及用于在浏览器中下载和打印的包装器。

部分结构

  • 部分名称,可选
  • 部分标题,可选
  • 部分内容,必需

部分类型

  • 键值对(kv)
key1 value1
key2 value2
  • 表格(tsv)
field1 field2 field3
value1 value2 value3
value4 value5 value6
  • 原始二维数组

示例

$name = 'name1';
// body [['field1'=>'', 'field2'=>'', ...], ...]
$data = [['f1'=>'v1', 'f2'=>'v2'], ['f1'=>'v3', 'f2'=>'v4']];
// head [['title'=>'', 'field'=>'', 'type'=>''], ...]
$head = [['title'=>'t1', 'field'=>'f1', 'type'=>'string'], ['title'=>'t2', 'field'=>'f2', 'type'=>'int']];
// rule
$rules = [];
$s = new Section(Section::KV_SECTION, $name, $data, $head, $rules);
// SectionFile is a list of Section
$sf = new SectionFile([$s1]);
规则
  • showHead: 布尔值,默认 true
  • showName: 布尔值,默认 true
  • null: 字符串,默认 '-', 如果值为空时显示的字符串
  • skip: 数组,默认 [], 跳过的字段
  • prefix: 字符串,默认 '', 每行前添加的前缀
  • postfix: 字符串,默认 '', 每行后添加的后缀
  • del: 字符串,默认 '\t', 字段之间的分隔符
使用SectionFile类创建txt文件或excel文件
$txt1 = TxtFile::createFromSection($sf);
$excel1 = ExcelFile::createFromSection($sf);
// Download in browser
$excel1->download();
// Print to browser if supported
$txt1->printContent();