Book/xlswriter-Phpdoc专题
XLSWriter
目录
- 简介
- 安装/配置
- 预定义常量
- Vtiful\Kernel\Excel — The
Vtiful\Kernel\Excel class
- Vtiful\Kernel\Excel::addSheet — Vtiful\Kernel\Excel addSheet
- Vtiful\Kernel\Excel::autoFilter — Vtiful\Kernel\Excel autoFilter
- Vtiful\Kernel\Excel::constMemory — Vtiful\Kernel\Excel constMemory
- Vtiful\Kernel\Excel::__construct — Vtiful\Kernel\Excel constructor
- Vtiful\Kernel\Excel::data — Vtiful\Kernel\Excel data
- Vtiful\Kernel\Excel::fileName — Vtiful\Kernel\Excel fileName
- Vtiful\Kernel\Excel::getHandle — Vtiful\Kernel\Excel getHandle
- Vtiful\Kernel\Excel::header — Vtiful\Kernel\Excel header
- Vtiful\Kernel\Excel::insertFormula — Vtiful\Kernel\Excel insertFormula
- Vtiful\Kernel\Excel::insertImage — Vtiful\Kernel\Excel insertImage
- Vtiful\Kernel\Excel::insertText — Vtiful\Kernel\Excel insertText
- Vtiful\Kernel\Excel::mergeCells — Vtiful\Kernel\Excel mergeCells
- Vtiful\Kernel\Excel::output — Vtiful\Kernel\Excel output
- Vtiful\Kernel\Excel::setColumn — Vtiful\Kernel\Excel setColumn
- Vtiful\Kernel\Excel::setRow — Vtiful\Kernel\Excel setRow
- Vtiful\Kernel\Format — The
Vtiful\Kernel\Format class
- Vtiful\Kernel\Format::align — Vtiful\Kernel\Format align
- Vtiful\Kernel\Format::bold — Vtiful\Kernel\Format bold
- Vtiful\Kernel\Format::italic — Vtiful\Kernel\Format italic
- Vtiful\Kernel\Format::underline — Vtiful\Kernel\Format underline
简介
Create xlsx files and set cells and output xlsx files
类摘要
Vtiful\Kernel\Excel
class Vtiful\Kernel\Excel {
/* 方法 */
public <span
class="methodname">addSheet ( <span
class="type">string $sheetName )
public <span
class="methodname">autoFilter ( <span
class="type">string $scope )
public <span
class="methodname">constMemory ( <span
class="type">string $fileName [, <span
class="methodparam">string $sheetName
] )
public <span
class="methodname">__construct ( <span
class="methodparam">array $config )
public <span
class="methodname">data ( <span
class="type">array $data )
public <span
class="methodname">fileName ( <span
class="type">string $fileName [, <span
class="methodparam">string $sheetName
] )
public <span class="methodname">getHandle ( <span class="methodparam">void )
public <span
class="methodname">header ( <span
class="type">array $headerData )
public <span
class="methodname">insertFormula ( <span
class="methodparam">int $row , <span
class="methodparam">int $column ,
string
$formula )
public <span
class="methodname">insertImage ( <span
class="type">int $row , <span
class="type">int $column , <span
class="methodparam">string
$localImagePath )
public <span
class="methodname">insertText ( <span
class="type">int $row , <span
class="type">int $column , <span
class="methodparam">string<span
class="type">intdouble $data
[, string
$format ] )
public <span
class="methodname">mergeCells ( <span
class="type">string $scope , <span
class="methodparam">string $data )
public <span class="methodname">output ( void )
public <span
class="methodname">setColumn ( <span
class="type">string $range , <span
class="methodparam">float $width [,
resource
$format ] )
public <span
class="methodname">setRow ( <span
class="type">string $range , <span
class="methodparam">float $height [,
resource
$format ] )
}
Vtiful\Kernel\Excel::addSheet
Vtiful\Kernel\Excel addSheet
说明
public <span
class="methodname">Vtiful\Kernel\Excel::addSheet ( <span
class="methodparam">string $sheetName
)
Create a new worksheet in the xlsx file.
参数
sheetName
Worksheet name
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $fileObject->fileName('tutorial.xlsx', 'sheet_one')
->header(['name', 'age'])
->data([
['viest', 23],
['wjx', 23]
]);
$file->addSheet('sheet_two')
->header(['name', 'age'])
->data([
['james', 33],
['king', 33]
]);
$file->output();
?>
Vtiful\Kernel\Excel::autoFilter
Vtiful\Kernel\Excel autoFilter
说明
public <span
class="methodname">Vtiful\Kernel\Excel::autoFilter ( <span
class="methodparam">string $scope )
Add autofilter to a worksheet.
参数
scope
Cell start and end coordinate string.
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $excel->fileName('test.xlsx')
->header(['name', 'age'])
->data($data)
->autoFilter('A1:B11') // auto filter
->output();
?>
Vtiful\Kernel\Excel::constMemory
Vtiful\Kernel\Excel constMemory
说明
public <span
class="methodname">Vtiful\Kernel\Excel::constMemory ( <span
class="methodparam">string $fileName
[, string
$sheetName ] )
Write a large file with constant memory usage.
参数
fileName
XLSX file name
sheetName
Worksheet name
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => '/home/viest'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $instance->constMemory('tutorial.xlsx', 'sheet');
?>
Vtiful\Kernel\Excel::__construct
Vtiful\Kernel\Excel constructor
说明
public <span
class="methodname">Vtiful\Kernel\Excel::__construct ( <span
class="methodparam">array $config )
Vtiful\Kernel\Excel constructor, create a class object.
参数
config
XLSX file export configuration
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => '/home/viest'
];
$excelObject = new \Vtiful\Kernel\Excel($config);
?>
Vtiful\Kernel\Excel::data
Vtiful\Kernel\Excel data
说明
public <span
class="methodname">Vtiful\Kernel\Excel::data ( <span
class="methodparam">array $data )
Write a data in the worksheet.
参数
data
worksheet data
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $fileObject->fileName('tutorial.xlsx', 'sheet_one')
->header(['name', 'age'])
->data([
['viest', 23],
['wjx', 23],
]);
?>
Vtiful\Kernel\Excel::fileName
Vtiful\Kernel\Excel fileName
说明
public <span
class="methodname">Vtiful\Kernel\Excel::fileName ( <span
class="methodparam">string $fileName
[, string
$sheetName ] )
Create a brand new xlsx file and create a worksheet.
参数
fileName
XLSX file name
sheetName
Worksheet name
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => '/home/viest'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $instance->fileName('tutorial.xlsx', 'sheet');
?>
Vtiful\Kernel\Excel::getHandle
Vtiful\Kernel\Excel getHandle
说明
public <span class="methodname">Vtiful\Kernel\Excel::getHandle ( <span class="methodparam">void )
Get the xlsx text resource handle.
参数
此函数没有参数。
返回值
Resource
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $fileObject->fileName('tutorial.xlsx', 'sheet_one')
->header(['name', 'age']);
$handle = $file->getHandle();
?>
Vtiful\Kernel\Excel::header
Vtiful\Kernel\Excel header
说明
public <span
class="methodname">Vtiful\Kernel\Excel::header ( <span
class="methodparam">array $headerData
)
Write a header in the worksheet.
参数
headerData
worksheet header data
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $fileObject->fileName('tutorial.xlsx', 'sheet_one')
->header(['name', 'age']);
?>
Vtiful\Kernel\Excel::insertFormula
Vtiful\Kernel\Excel insertFormula
说明
public <span
class="methodname">Vtiful\Kernel\Excel::insertFormula ( <span
class="methodparam">int $row , <span
class="methodparam">int $column ,
string
$formula )
Insert calculation formula.
参数
row
cell row
column
cell column
formula
formula string
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$file = $excel->fileName("free.xlsx")
->header(['name', 'money']);
for($index = 1; $index < 10; $index++) {
$file->insertText($index, 0, 'viest');
$file->insertText($index, 1, 10);
}
$file->insertText(12, 0, "Total");
$file->insertFormula(12, 1, '=SUM(B2:B11)'); // insert formula
$file->output();
Vtiful\Kernel\Excel::insertImage
Vtiful\Kernel\Excel insertImage
说明
public <span
class="methodname">Vtiful\Kernel\Excel::insertImage ( <span
class="methodparam">int $row , <span
class="methodparam">int $column ,
string
$localImagePath )
Insert a local image into the cell.
参数
row
cell row
column
cell column
localImagePath
local image path
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$file = $excel->fileName("free.xlsx");
$file->insertImage(5, 0, '/vagrant/ASW-G-66.jpg');
$file->output();
Vtiful\Kernel\Excel::insertText
Vtiful\Kernel\Excel insertText
说明
public <span
class="methodname">Vtiful\Kernel\Excel::insertText ( <span
class="methodparam">int $row , <span
class="methodparam">int $column ,
string<span
class="type">intdouble $data
[, string
$format ] )
Write text in a cell.
参数
row
cell row
column
cell column
data
data to be written
format
String format
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$file = $excel->fileName("free.xlsx")
->header(['name', 'money']);
for ($index = 0; $index < 10; $index++) {
$file->insertText($index+1, 0, 'viest');
$file->insertText($index+1, 1, 10000, '#,##0');
}
$textFile->output();
Vtiful\Kernel\Excel::mergeCells
Vtiful\Kernel\Excel mergeCells
说明
public <span
class="methodname">Vtiful\Kernel\Excel::mergeCells ( <span
class="methodparam">string $scope ,
string
$data )
Merge Cells.
参数
scope
cell start and end coordinate strings
data
string data
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName("test.xlsx")
->mergeCells('A1:C1', 'Merge cells')
->output();
Vtiful\Kernel\Excel::output
Vtiful\Kernel\Excel output
说明
public <span class="methodname">Vtiful\Kernel\Excel::output ( <span class="methodparam">void )
Output xlsx file to disk.
参数
此函数没有参数。
返回值
XLSX file path;
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$file = $fileObject->fileName('tutorial.xlsx', 'sheet_one')
->header(['name', 'age'])
->data([
['viest', 23],
['wjx', 23],
]);
$path = $file->output();
?>
Vtiful\Kernel\Excel::setColumn
Vtiful\Kernel\Excel setColumn
说明
public <span
class="methodname">Vtiful\Kernel\Excel::setColumn ( <span
class="methodparam">string $range ,
float
$width [, <span
class="type">resource $format ] )
Set the format of the column.
参数
range
cell start and end coordinate strings
width
column width
format
cell format resource
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$boldStyle = \Vtiful\Kernel\Format::bold($fileHandle);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $boldStyle)
->output();
Vtiful\Kernel\Excel::setRow
Vtiful\Kernel\Excel setRow
说明
public <span
class="methodname">Vtiful\Kernel\Excel::setRow ( <span
class="methodparam">string $range ,
float
$height [, <span
class="type">resource $format ] )
Set the format of the column.
参数
range
cell start and end coordinate strings
height
row height
format
cell format resource
返回值
Vtiful\Kernel\Excel instance
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$boldStyle = \Vtiful\Kernel\Format::bold($fileHandle);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setRow('A1', 20, $boldStyle,)
->output();
简介
Create a cell format object
类摘要
Vtiful\Kernel\Format
class Vtiful\Kernel\Format {
/* Constants */
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_LEFT =
1 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER =
2 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_RIGHT =
3 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_FILL =
4 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_JUSTIFY
= 5 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER_ACROSS <span
class="initializer"> = 6 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_DISTRIBUTED <span
class="initializer"> = 7 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_TOP <span
class="initializer"> = 8 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_BOTTOM <span
class="initializer"> = 9 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER <span
class="initializer"> = 10 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_JUSTIFY <span
class="initializer"> = 11 ;
const int
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_DISTRIBUTED <span
class="initializer"> = 12 ;
const int
Vtiful\Kernel\Format::UNDERLINE_SINGLE =
1 ;
const int
Vtiful\Kernel\Format::UNDERLINE_DOUBLE =
2 ;
const int
Vtiful\Kernel\Format::UNDERLINE_SINGLE_ACCOUNTING <span
class="initializer"> = 3 ;
const int
Vtiful\Kernel\Format::UNDERLINE_DOUBLE_ACCOUNTING <span
class="initializer"> = 4 ;
/* 方法 */
public <span
class="methodname">align ( <span
class="type">resource $handle , <span
class="methodparam">int $style )
public <span
class="methodname">bold ( <span
class="type">resource $handle )
public <span
class="methodname">italic ( <span
class="type">resource $handle )
public <span
class="methodname">underline ( <span
class="type">resource $handle , <span
class="methodparam">int $style )
}
预定义常量
Vtiful\Kernel\Format::FORMAT_ALIGN_LEFT
Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER
Vtiful\Kernel\Format::FORMAT_ALIGN_RIGHT
Vtiful\Kernel\Format::FORMAT_ALIGN_FILL
Vtiful\Kernel\Format::FORMAT_ALIGN_JUSTIFY
Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER_ACROSS
Vtiful\Kernel\Format::FORMAT_ALIGN_DISTRIBUTED
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_TOP
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_BOTTOM
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_JUSTIFY
Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_DISTRIBUTED
Vtiful\Kernel\Format::UNDERLINE_SINGLE
Vtiful\Kernel\Format::UNDERLINE_DOUBLE
Vtiful\Kernel\Format::UNDERLINE_SINGLE_ACCOUNTING
Vtiful\Kernel\Format::UNDERLINE_DOUBLE_ACCOUNTING
Vtiful\Kernel\Format::align
Vtiful\Kernel\Format align
说明
public <span
class="methodname">Vtiful\Kernel\Format::align ( <span
class="methodparam">resource $handle
, int
$style )
set cell align
参数
handle
xlsx file handle
style
Vtiful\Kernel\Format constant
返回值
Resource
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$alignStyle = \Vtiful\Kernel\Format::align($fileHandle, \Vtiful\Kernel\Format::FORMAT_ALIGN_LEFT);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $align)
->output();
?>
Vtiful\Kernel\Format::bold
Vtiful\Kernel\Format bold
说明
public <span
class="methodname">Vtiful\Kernel\Format::bold ( <span
class="methodparam">resource $handle
)
Vtiful\Kernel\Format bold format
参数
handle
xlsx file handle
返回值
Resource
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$boldStyle = \Vtiful\Kernel\Format::bold($fileHandle);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $boldStyle)
->output();
?>
Vtiful\Kernel\Format::italic
Vtiful\Kernel\Format italic
说明
public <span
class="methodname">Vtiful\Kernel\Format::italic ( <span
class="methodparam">resource $handle
)
Vtiful\Kernel\Format italic format
参数
handle
xlsx file handle
返回值
Resource
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$italicStyle = \Vtiful\Kernel\Format::italic($fileHandle);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $italicStyle)
->output();
?>
Vtiful\Kernel\Format::underline
Vtiful\Kernel\Format underline
说明
public <span
class="methodname">Vtiful\Kernel\Format::underline ( <span
class="methodparam">resource $handle
, int
$style )
Vtiful\Kernel\Format underline format
参数
handle
xlsx file handle
style
Vtiful\Kernel\Format constant
返回值
Resource
范例
示例 #1 example
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('tutorial01.xlsx');
$fileHandle = $fileObject->getHandle();
$underlineStyle = \Vtiful\Kernel\Format::underline($fileHandle, \Vtiful\Kernel\Format::UNDERLINE_SINGLE);
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $underlineStyle)
->output();
?>