初始化PHP-Xlswrite扩展

This commit is contained in:
ykxiao
2024-03-05 10:01:08 +08:00
commit 879cf9584d
2483 changed files with 1054962 additions and 0 deletions

10
tests/001.phpt Normal file
View File

@ -0,0 +1,10 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
echo "xlswriter extension is available";
?>
--EXPECT--
xlswriter extension is available

23
tests/002.phpt Normal file
View File

@ -0,0 +1,23 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
var_dump($excel);
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
NULL
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

23
tests/003.phpt Normal file
View File

@ -0,0 +1,23 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileFd = $excel->fileName('tutorial01.xlsx');
var_dump($fileFd);
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(23) "./tests/tutorial01.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

24
tests/004.phpt Normal file
View File

@ -0,0 +1,24 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileFd = $excel->fileName('tutorial01.xlsx');
$setHeader = $fileFd->header(['Item', 'Cost']);
var_dump($setHeader);
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(23) "./tests/tutorial01.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

19
tests/005.phpt Normal file
View File

@ -0,0 +1,19 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('005.xlsx')
->header(['Item', 'Cost'])
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/005.xlsx');
?>
--EXPECT--
string(16) "./tests/005.xlsx"

14
tests/006.phpt Normal file
View File

@ -0,0 +1,14 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$handle = $excel->fileName('tutorial01.xlsx')
->getHandle();
var_dump($handle);
?>
--EXPECT--
resource(4) of type (xlsx)

18
tests/007.phpt Normal file
View File

@ -0,0 +1,18 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$handle = $excel->fileName('tutorial01.xlsx')->getHandle();
$format = new \Vtiful\Kernel\Format($handle);
$boldFormat = $format->bold()->toResource();
var_dump($boldFormat);
?>
--EXPECT--
resource(5) of type (xlsx)

18
tests/008.phpt Normal file
View File

@ -0,0 +1,18 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$handle = $excel->fileName('tutorial01.xlsx')->getHandle();
$format = new \Vtiful\Kernel\Format($handle);
$italicStyle = $format->italic()->toResource();
var_dump($italicStyle);
?>
--EXPECT--
resource(5) of type (xlsx)

18
tests/009.phpt Normal file
View File

@ -0,0 +1,18 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$handle = $excel->fileName('tutorial01.xlsx')->getHandle();
$format = new \Vtiful\Kernel\Format($handle);
$underlineStyle = $format->underline(\Vtiful\Kernel\Format::UNDERLINE_SINGLE)->toResource();
var_dump($underlineStyle);
?>
--EXPECT--
resource(5) of type (xlsx)

31
tests/010.phpt Normal file
View File

@ -0,0 +1,31 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel_one = new \Vtiful\Kernel\Excel($config);
$fileOne = $excel_one->fileName('010-1.xlsx')
->header(['test1'])
->data([
['data1'],
])
->output();
$excel_two = new \Vtiful\Kernel\Excel($config);
$fileTwo = $excel_two->fileName('010-2.xlsx')
->header(['test2'])
->data([
['data2'],
])
->output();
var_dump($fileOne,$fileTwo);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/010-1.xlsx');
@unlink(__DIR__ . '/010-2.xlsx');
?>
--EXPECT--
string(18) "./tests/010-1.xlsx"
string(18) "./tests/010-2.xlsx"

29
tests/011.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('11.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setColumn('A:A', 200, $boldStyle)
->setColumn('B:B', 200, null)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/11.xlsx');
?>
--EXPECT--
string(15) "./tests/11.xlsx"

34
tests/012.phpt Normal file
View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('12.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21],
['abc', 21]
])
->setRow('A1', 200, $boldStyle)
->setRow('A2:A3', 200, $boldStyle)
->setRow('A4:A4', 200, null)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/12.xlsx');
?>
--EXPECT--
string(15) "./tests/12.xlsx"

27
tests/013.phpt Normal file
View File

@ -0,0 +1,27 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$textFile = $excel->fileName("13.xlsx")
->header(['name', 'age']);
for ($index = 0; $index < 10; $index++) {
$textFile->insertText($index+1, 0, 'vikin');
$textFile->insertText($index+1, 1, 1000, '#,##0');
}
$filePath = $textFile->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/13.xlsx');
?>
--EXPECT--
string(15) "./tests/13.xlsx"

32
tests/014.phpt Normal file
View File

@ -0,0 +1,32 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$freeFile = $excel->fileName("14.xlsx")
->header(['name', 'money']);
for($index = 1; $index <= 10; $index++) {
$freeFile->insertText($index, 0, 'vikin');
$freeFile->insertText($index, 1, 10);
}
$freeFile->insertText(12, 0, "Total");
$freeFile->insertFormula(12, 1, '=SUM(B2:B11)');
$freeFile->insertText(13, 0, "Total (default format)");
$freeFile->insertFormula(13, 1, '=SUM(B2:B11)', null);
$filePath = $freeFile->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/14.xlsx');
?>
--EXPECT--
string(15) "./tests/14.xlsx"

27
tests/015.phpt Normal file
View File

@ -0,0 +1,27 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName("15.xlsx")
->header(['name', 'age'])
->data([
['one', 10],
['two', 20],
['three', 30],
])
->autoFilter("A1:B3")
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/15.xlsx');
?>
--EXPECT--
string(15) "./tests/15.xlsx"

22
tests/016.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName("16.xlsx")
->mergeCells('A1:C1', 'Merge cells')
->mergeCells('A2:C2', 'Merge cells, explicit null (default) format', null)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/16.xlsx');
?>
--EXPECT--
string(15) "./tests/16.xlsx"

25
tests/018.phpt Normal file
View File

@ -0,0 +1,25 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName("18.xlsx");
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->data([['wjx', 21]]);
$filePath = $fileObject->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/18.xlsx');
?>
--EXPECT--
string(15) "./tests/18.xlsx"

32
tests/activate_sheet.phpt Normal file
View File

@ -0,0 +1,32 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject->fileName('activate_sheet.xlsx')
->header(['name', 'age'])
->data([
['viest', 21],
['viest', 22],
['viest', 23],
]);
$fileObject->addSheet('twoSheet')
->header(['name', 'age'])
->data([['vikin', 22]]);
var_dump($fileObject->activateSheet('twoSheet'));
$fileObject->output();
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/activate_sheet.xlsx');
?>
--EXPECT--
bool(true)

View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_axis_name_x.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_AREA);
$chartResource = $chart
->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
->axisNameX('Test number')
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_axis_name_x.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_axis_name_y.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_AREA);
$chartResource = $chart
->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
->axisNameY('Sample length (mm)')
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_axis_name_y.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

38
tests/chart_line.phpt Normal file
View File

@ -0,0 +1,38 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_line.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_LINE);
$chartResource = $chart->series('Sheet1!$A$2:$A$7')->toResource();
$filePath = $fileObject->header(['number'])
->data([
[10],
[40],
[50],
[20],
[10],
[50],
])
->insertChart(0, 3, $chartResource)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_line.xlsx');
?>
--EXPECT--
string(23) "./tests/chart_line.xlsx"

26
tests/chart_resource.phpt Normal file
View File

@ -0,0 +1,26 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_resource.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_LINE);
$chartResource = $chart->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
//
?>
--EXPECT--
resource(5) of type (xlsx)

28
tests/chart_series.phpt Normal file
View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_series.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_COLUMN);
$chartResource = $chart->series('Sheet1!$A$1:$A$5')
->series('Sheet1!$B$1:$B$5')
->series('Sheet1!$C$1:$C$5')
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_series.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_series_name.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_AREA);
$chartResource = $chart
->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
->seriesName('=Sheet1!$B$1')
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_series_name.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

29
tests/chart_style.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_style.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_AREA);
$chartResource = $chart
->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
->seriesName('=Sheet1!$B$1')
->style(11)
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_style.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

28
tests/chart_title.phpt Normal file
View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('chart_title.xlsx');
$fileHandle = $fileObject->getHandle();
$chart = new \Vtiful\Kernel\Chart($fileHandle, \Vtiful\Kernel\Chart::CHART_AREA);
$chartResource = $chart
->series('=Sheet1!$B$2:$B$7', '=Sheet1!$A$2:$A$7')
->title('Results of sample analysis')
->toResource();
var_dump($chartResource);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/chart_title.xlsx');
?>
--EXPECT--
resource(5) of type (xlsx)

22
tests/close.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('close.xlsx')
->header(['Item', 'Cost'])
->output();
$excel->close();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/close.xlsx');
?>
--EXPECT--
string(18) "./tests/close.xlsx"

View File

@ -0,0 +1,26 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('A'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('AC'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('AB'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('AZ'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('ABC'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('ADE'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('AS'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('XF'));
var_dump(\Vtiful\Kernel\Excel::columnIndexFromString('ST'));
?>
--EXPECT--
int(0)
int(28)
int(27)
int(51)
int(730)
int(784)
int(44)
int(629)
int(513)

25
tests/const_memory.phpt Normal file
View File

@ -0,0 +1,25 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$excel = new \Vtiful\Kernel\Excel([
'path' => './tests',
]);
$fileObject = $excel->constMemory('const_memory.xlsx');
$fileHandle = $fileObject->getHandle();
$path = $fileObject->header(['name', 'age'])
->data([['viest', 21]])
->output();
var_dump($path);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/const_memory.xlsx');
?>
--EXPECT--
string(25) "./tests/const_memory.xlsx"

View File

@ -0,0 +1,77 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
try {
$excel = new \Vtiful\Kernel\Excel([
'path' => './',
]);
$fileObject = $excel->constMemory('const_memory_index_out_range.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->mergeCells('A1:C1', 'aaaa')
->output();
} catch (\Vtiful\Kernel\Exception $exception) {
echo $exception->getCode() . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
}
try {
$excel = new \Vtiful\Kernel\Excel([
'path' => './',
]);
$fileObject = $excel->constMemory('const_memory_index_out_range.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->setRow('A1', 200)
->output();
} catch (\Vtiful\Kernel\Exception $exception) {
echo $exception->getCode() . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
}
try {
$excel = new \Vtiful\Kernel\Excel([
'path' => './',
]);
$fileObject = $excel->constMemory('const_memory_index_out_range.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$boldStyle = $format->bold()->toResource();
$fileObject->header(['name', 'age'])
->data([['viest', 21]])
->autoFilter('A1:C1')
->output();
} catch (\Vtiful\Kernel\Exception $exception) {
echo $exception->getCode() . PHP_EOL;
echo $exception->getMessage() . PHP_EOL;
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/const_memory_index_out_range.xlsx');
?>
--EXPECT--
170
In const memory mode, you cannot modify the placed cells
170
In const memory mode, you cannot modify the placed cells
170
In const memory mode, you cannot modify the placed cells

60
tests/data_reference.phpt Normal file
View File

@ -0,0 +1,60 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$data = [
[23],
[21],
[21],
[21],
];
foreach($data as &$line) {
$line[0]++;
}
$excel = new \Vtiful\Kernel\Excel([
'path' => './tests',
]);
$fileObject = $excel->constMemory('data_reference.xlsx', NULL, false);
$fileHandle = $fileObject->getHandle();
$path = $fileObject->header(['age'])
->data($data)
->output();
$excel->openFile('data_reference.xlsx')
->openSheet();
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/data_reference.xlsx');
?>
--EXPECT--
array(1) {
[0]=>
string(3) "age"
}
array(1) {
[0]=>
int(24)
}
array(1) {
[0]=>
int(22)
}
array(1) {
[0]=>
int(22)
}

View File

@ -0,0 +1,62 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$excel = new \Vtiful\Kernel\Excel([
'path' => './tests',
]);
$fileObject = $excel->constMemory('data_string_key.xlsx', NULL, false);
$fileHandle = $fileObject->getHandle();
$path = $fileObject->header(['name', 'age'])
->data([
['name'=>'viest', 'age' => 21, 1 => 23],
['name'=>'viest', 'age' => 21],
['name'=>'viest', 'age' => 21],
['viest', 21],
])
->output();
$excel->openFile('data_string_key.xlsx')
->openSheet();
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/data_string_key.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
string(4) "name"
[1]=>
string(3) "age"
}
array(2) {
[0]=>
string(5) "viest"
[1]=>
int(23)
}
array(2) {
[0]=>
string(5) "viest"
[1]=>
int(21)
}
array(2) {
[0]=>
string(5) "viest"
[1]=>
int(21)
}

41
tests/default_format.phpt Normal file
View File

@ -0,0 +1,41 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('default_format.xlsx');
$format = new \Vtiful\Kernel\Format($excel->getHandle());
$colorOneStyle = $format
->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)
->border(\Vtiful\Kernel\Format::BORDER_DASH_DOT)
->toResource();
$format = new \Vtiful\Kernel\Format($excel->getHandle());
$colorTwoStyle = $format
->fontColor(\Vtiful\Kernel\Format::COLOR_GREEN)
->toResource();
$filePath = $excel
// Apply the first style as the default
->defaultFormat($colorOneStyle)
->header(['hello', 'xlswriter'])
// Apply the second style as the default style
->defaultFormat($colorTwoStyle)
->data([
['hello', 'xlswriter'],
])
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/default_format.xlsx');
?>
--EXPECT--
string(27) "./tests/default_format.xlsx"

23
tests/exist_sheet.phpt Normal file
View File

@ -0,0 +1,23 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject->fileName('exist_sheet.xlsx')
->addSheet('twoSheet');
var_dump($fileObject->existSheet('twoSheet'));
var_dump($fileObject->existSheet('notFoundSheet'));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/exist_sheet.xlsx');
?>
--EXPECT--
bool(true)
bool(false)

44
tests/first.phpt Normal file
View File

@ -0,0 +1,44 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
try {
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->setCurrentSheetHide();
} catch (\Exception $exception) {
var_dump($exception->getCode());
var_dump($exception->getMessage());
}
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('first.xlsx', 'sheet1')
->addSheet('sheet2')
->setCurrentSheetIsFirst()
->output();
var_dump($excel);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/first.xlsx');
?>
--EXPECT--
int(130)
string(51) "Please create a file first, use the filename method"
object(Vtiful\Kernel\Excel)#3 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(18) "./tests/first.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

75
tests/fix-207.phpt Normal file
View File

@ -0,0 +1,75 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('fix-207.xlsx')
->header(['Name', 'Code'])
->data([
['Viest', '00024']
])
->output();
$dataOne = $excel->openFile('fix-207.xlsx')
->openSheet()
->setType([
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_STRING,
])
->getSheetData();
$dataTwo = $excel->openFile('fix-207.xlsx')
->openSheet()
->setType([
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_INT,
])
->getSheetData();
var_dump($dataOne);
var_dump($dataTwo);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/fix-207.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
array(2) {
[0]=>
string(4) "Name"
[1]=>
string(4) "Code"
}
[1]=>
array(2) {
[0]=>
string(5) "Viest"
[1]=>
string(5) "00024"
}
}
array(2) {
[0]=>
array(2) {
[0]=>
string(4) "Name"
[1]=>
string(4) "Code"
}
[1]=>
array(2) {
[0]=>
string(5) "Viest"
[1]=>
int(24)
}
}

49
tests/fix-243.phpt Normal file
View File

@ -0,0 +1,49 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('fix-243.xlsx')
->header(['NumberToString', 'Number'])
->data([
['01234567', '01234567']
])
->output();
$data = $excel->openFile('fix-243.xlsx')
->openSheet()
->setType([
\Vtiful\Kernel\Excel::TYPE_STRING,
])
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/fix-243.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
array(2) {
[0]=>
string(14) "NumberToString"
[1]=>
string(6) "Number"
}
[1]=>
array(2) {
[0]=>
string(8) "01234567"
[1]=>
int(1234567)
}
}

38
tests/format_align.phpt Normal file
View File

@ -0,0 +1,38 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_align.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format->align(
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $alignStyle)
->setRow('A2:A3', 50, $alignStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_align.xlsx');
?>
--EXPECT--
string(25) "./tests/format_align.xlsx"

View File

@ -0,0 +1,37 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_background.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$style = $format->background(
\Vtiful\Kernel\Format::COLOR_RED,
\Vtiful\Kernel\Format::PATTERN_LIGHT_UP
)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $style)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_background.xlsx');
?>
--EXPECT--
string(30) "./tests/format_background.xlsx"

38
tests/format_border.phpt Normal file
View File

@ -0,0 +1,38 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border.xlsx');
?>
--EXPECT--
string(26) "./tests/format_border.xlsx"

View File

@ -0,0 +1,41 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border_color.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->borderColor(\Vtiful\Kernel\Format::COLOR_ORANGE)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border_color.xlsx');
?>
--EXPECT--
string(32) "./tests/format_border_color.xlsx"

View File

@ -0,0 +1,46 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border_color_of_the_four_side_1.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->borderColorOfTheFourSides(
\Vtiful\Kernel\Format::COLOR_ORANGE, // top
\Vtiful\Kernel\Format::COLOR_GREEN, // right
\Vtiful\Kernel\Format::COLOR_RED, // bottom
\Vtiful\Kernel\Format::COLOR_YELLOW // left
)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border_color_of_the_four_side_1.xlsx');
?>
--EXPECT--
string(51) "./tests/format_border_color_of_the_four_side_1.xlsx"

View File

@ -0,0 +1,46 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border_color_of_the_four_side_2.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->borderColorOfTheFourSides(
NULL, // top
\Vtiful\Kernel\Format::COLOR_GREEN, // right
\Vtiful\Kernel\Format::COLOR_RED, // bottom
NULL // left
)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border_color_of_the_four_side_2.xlsx');
?>
--EXPECT--
string(51) "./tests/format_border_color_of_the_four_side_2.xlsx"

View File

@ -0,0 +1,46 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border_of_the_four_side_1.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->borderOfTheFourSides(
\Vtiful\Kernel\Format::BORDER_THIN, // top
\Vtiful\Kernel\Format::BORDER_MEDIUM, // right
\Vtiful\Kernel\Format::BORDER_DASHED, // bottom
\Vtiful\Kernel\Format::BORDER_DOTTED // left
)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border_of_the_four_side_1.xlsx');
?>
--EXPECT--
string(45) "./tests/format_border_of_the_four_side_1.xlsx"

View File

@ -0,0 +1,46 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_border_of_the_four_side_2.xlsx');
$fileHandle = $fileObject->getHandle();
$data = [
['viest1', 21, 100, "A"],
['viest2', 20, 80, "B"],
['viest3', 22, 70, "C"],
];
$format = new \Vtiful\Kernel\Format($fileHandle);
$borderStyle = $format
->border(\Vtiful\Kernel\Format::BORDER_THIN)
->borderOfTheFourSides(
NULL, // top
\Vtiful\Kernel\Format::BORDER_THICK, // right
\Vtiful\Kernel\Format::BORDER_DOUBLE, // bottom
NULL // left
)
->toResource();
$filePath = $fileObject->header(['name', 'age', 'score', 'level'])
->data($data)
->setRow('A1', 20, $borderStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_border_of_the_four_side_2.xlsx');
?>
--EXPECT--
string(45) "./tests/format_border_of_the_four_side_2.xlsx"

37
tests/format_font.phpt Normal file
View File

@ -0,0 +1,37 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_font.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$fontStyle = $format->font('Calibri')->toResource();
// Local Test
// $fontStyle = $format->font('华文楷体')->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $fontStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_font.xlsx');
?>
--EXPECT--
string(24) "./tests/format_font.xlsx"

View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_font_color.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $colorStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_font_color.xlsx');
?>
--EXPECT--
string(30) "./tests/format_font_color.xlsx"

View File

@ -0,0 +1,35 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_font_size.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$style = $format->fontSize(30)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $style)
->setRow('A2:A3', 50, $style)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_font_size.xlsx');
?>
--EXPECT--
string(29) "./tests/format_font_size.xlsx"

View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_font_strikeout.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$style = $format->strikeout()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setRow('A1', 50, $style)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_font_strikeout.xlsx');
?>
--EXPECT--
string(34) "./tests/format_font_strikeout.xlsx"

34
tests/format_number.phpt Normal file
View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_number.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$numberStyle = $format->number('#,##0')->toResource();
$filePath = $fileObject->header(['name', 'balance'])
->data([
['viest', 10000],
['wjx', 100000]
])
->setColumn('B:B', 50, $numberStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_number.xlsx');
?>
--EXPECT--
string(26) "./tests/format_number.xlsx"

View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_unlocked.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$unlockedStyle = $format->unlocked()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['wjx', 21]
])
->setRow('A2', 50, $unlockedStyle)
->protection()
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_unlocked.xlsx');
?>
--EXPECT--
string(28) "./tests/format_unlocked.xlsx"

34
tests/format_wrap.phpt Normal file
View File

@ -0,0 +1,34 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('format_wrap.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$wrapStyle = $format->wrap()->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
["vvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvvvvvvvvvvvvvvvvvvvvv", 21],
['wjx', 21]
])
->setRow('A2', 50, $wrapStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/format_wrap.xlsx');
?>
--EXPECT--
string(24) "./tests/format_wrap.xlsx"

31
tests/freeze_panes.phpt Normal file
View File

@ -0,0 +1,31 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests',
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('freeze_panes.xlsx');
$fileHandle = $fileObject->getHandle();
$filePath = $fileObject->freezePanes(1, 0)
->header(['name', 'age']);
for ($index = 0; $index < 100; $index++) {
$fileObject->insertText($index + 1, 0, 'wjx');
$fileObject->insertText($index + 1, 1, 21);
}
var_dump($fileObject->output());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/freeze_panes.xlsx');
?>
--EXPECT--
string(25) "./tests/freeze_panes.xlsx"

View File

@ -0,0 +1,27 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject->fileName('get_set_current_line.xlsx')
->header(['name', 'age'])
->setCurrentLine(2)
->data([
['viest', 21],
]);
var_dump($fileObject->getCurrentLine());
$fileObject->output();
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/get_set_current_line.xlsx');
?>
--EXPECT--
int(3)

29
tests/gridlines.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName("gridlines.xlsx");
$fileObject->header(['name', 'age'])
->gridline(\Vtiful\Kernel\Excel::GRIDLINES_HIDE_ALL)
->data([
['viest', 21],
['viest', 22],
['viest', 23],
]);
$filePath = $fileObject->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gridlines.xlsx');
?>
--EXPECT--
string(22) "./tests/gridlines.xlsx"

33
tests/header_format.phpt Normal file
View File

@ -0,0 +1,33 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName('header_format.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format->align(
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
)->toResource();
$setHeader = $fileObject
->header(['Item', 'Cost'], $alignStyle)
->output();
var_dump($setHeader);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/header_format.xlsx');
?>
--EXPECT--
string(26) "./tests/header_format.xlsx"

44
tests/hide.phpt Normal file
View File

@ -0,0 +1,44 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
try {
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->setCurrentSheetHide();
} catch (\Exception $exception) {
var_dump($exception->getCode());
var_dump($exception->getMessage());
}
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('hide.xlsx', 'sheet1')
->addSheet('sheet2')
->setCurrentSheetHide()
->output();
var_dump($excel);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/hide.xlsx');
?>
--EXPECT--
int(130)
string(51) "Please create a file first, use the filename method"
object(Vtiful\Kernel\Excel)#3 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(17) "./tests/hide.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('image_no_styles.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->insertImage(3, 0, __DIR__ . '/../resource/pecl.png')
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/image_no_styles.xlsx');
?>
--EXPECT--
string(28) "./tests/image_no_styles.xlsx"

View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('image_width_height_styles.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->insertImage(3, 0, __DIR__ . '/../resource/pecl.png', 10, 20)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/image_width_height_styles.xlsx');
?>
--EXPECT--
string(38) "./tests/image_width_height_styles.xlsx"

21
tests/include/skipif.inc Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* Skip Disable Reader
*
* @return void
*
* @author viest
*/
function skip_disable_reader() {
if (!method_exists('\Vtiful\Kernel\Excel', 'openFile')) {
print "skip";
}
}
(function(){
if (!extension_loaded("xlswriter")) {
print "skip";
}
})();

22
tests/insert_comment.phpt Normal file
View File

@ -0,0 +1,22 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('insert_comment.xlsx')
->header(['Item', 'Cost'])
->insertComment(0,1,'comment')
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_comment.xlsx');
?>
--EXPECT--
string(27) "./tests/insert_comment.xlsx"

View File

@ -0,0 +1,25 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('insert_date_custom_format.xlsx');
$filePath = $fileObject->header(['date'])
->insertDate(1, 0, time(), 'mmm d yyyy hh:mm AM/PM')
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_date_custom_format.xlsx');
?>
--EXPECT--
string(38) "./tests/insert_date_custom_format.xlsx"

View File

@ -0,0 +1,25 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('insert_date_default_format.xlsx');
$filePath = $fileObject->header(['date'])
->insertDate(1, 0, time())
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_date_default_format.xlsx');
?>
--EXPECT--
string(39) "./tests/insert_date_default_format.xlsx"

View File

@ -0,0 +1,30 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('insert_date_resource_format.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
$filePath = $fileObject->header(['date'])
->insertDate(1, 0, time(), 'mmm d yyyy hh:mm AM/PM', $colorStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_date_resource_format.xlsx');
?>
--EXPECT--
string(40) "./tests/insert_date_resource_format.xlsx"

View File

@ -0,0 +1,32 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$textFile = $excel->fileName("insert_text_resource_format.xlsx")
->header(['name', 'age']);
$fileHandle = $textFile->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
for ($index = 0; $index < 10; $index++) {
$textFile->insertText($index+1, 0, 'vikin');
$textFile->insertText($index+1, 1, 1000, '#,##0', $colorStyle);
}
$filePath = $textFile->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_text_resource_format.xlsx');
?>
--EXPECT--
string(40) "./tests/insert_text_resource_format.xlsx"

View File

@ -0,0 +1,36 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('insert_url_format.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format->align(
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
)->toResource();
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->insertUrl(3, 0, 'https://github.com', NULL, NULL, $alignStyle)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_url_format.xlsx');
?>
--EXPECT--
string(30) "./tests/insert_url_format.xlsx"

View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('insert_url_no_format.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->insertUrl(3, 0, 'https://github.com')
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/insert_url_no_format.xlsx');
?>
--EXPECT--
string(33) "./tests/insert_url_no_format.xlsx"

31
tests/margins.phpt Normal file
View File

@ -0,0 +1,31 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('margins.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setPaper(\Vtiful\Kernel\Excel::PAPER_A3)
->setLandscape()
->setMargins(1, 1, 2, 2)
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/margins.xlsx');
?>
--EXPECT--
string(20) "./tests/margins.xlsx"

View File

@ -0,0 +1,46 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName("merge_cell_type_writer.xlsx")
->mergeCells('A1:C1', 1)
->mergeCells('A2:D2', '2')
->mergeCells('A3:E3', 3.001)
->output();
$data = $excel->openFile('merge_cell_type_writer.xlsx')
->openSheet()
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/merge_cell_type_writer.xlsx');
?>
--EXPECT--
array(3) {
[0]=>
array(1) {
[0]=>
int(1)
}
[1]=>
array(1) {
[0]=>
int(2)
}
[2]=>
array(1) {
[0]=>
float(3.001)
}
}

44
tests/multiple_file.phpt Normal file
View File

@ -0,0 +1,44 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests',
];
$lastFilePath = NULL;
for ($index = 0; $index < 100; $index++) {
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('multiple_file' . $index . '.xlsx');
$fileHandle = $fileObject->getHandle();
$format = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format->align(
\Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
\Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
)->toResource();
$lastFilePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21],
])
->setRow('A1', 50, $alignStyle)
->setRow('A2:A3', 50, $alignStyle)
->output();
}
var_dump($lastFilePath);
?>
--CLEAN--
<?php
for ($index = 0; $index < 100; $index++) {
@unlink(__DIR__ . '/multiple_file' . $index . '.xlsx');
}
?>
--EXPECT--
string(28) "./tests/multiple_file99.xlsx"

35
tests/open_xlsx_file.phpt Normal file
View File

@ -0,0 +1,35 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_file.xlsx')
->header(['Item', 'Cost'])
->output();
$data = $excel->openFile('open_xlsx_file.xlsx');
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_file.xlsx');
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(27) "./tests/open_xlsx_file.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

View File

@ -0,0 +1,24 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
try {
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->openFile('tutorial_not_found.xlsx');
} catch (Vtiful\Kernel\Exception $exception) {
var_dump($exception->getMessage());
}
?>
--CLEAN--
<?php
//
?>
--EXPECT--
string(57) "File not found, file path:./tests/tutorial_not_found.xlsx"

View File

@ -0,0 +1,35 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_data.xlsx')
->header(['Item', 'Cost'])
->output();
$data = $excel->openFile('open_xlsx_get_data.xlsx')
->openSheet()
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_data.xlsx');
?>
--EXPECT--
array(1) {
[0]=>
array(2) {
[0]=>
string(4) "Item"
[1]=>
string(4) "Cost"
}
}

View File

@ -0,0 +1,41 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_data_bignumbers.xlsx')
->header(['Item'])
->data([
['9999999999999999999999999999999999999999999999999999999999999'],
])
->output();
$data = $excel->openFile('open_xlsx_get_data_bignumbers.xlsx')
->openSheet()
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_data_bignumbers.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
array(1) {
[0]=>
string(4) "Item"
}
[1]=>
array(1) {
[0]=>
string(61) "9999999999999999999999999999999999999999999999999999999999999"
}
}

View File

@ -0,0 +1,106 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_data_skip_empty.xlsx')
->header(['', 'Cost'])
->data([
[],
['viest', '']
])
->output();
$data = $excel->openFile('open_xlsx_get_data_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_CELLS)
->getSheetData();
var_dump($data);
$data = $excel->openFile('open_xlsx_get_data_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_ROW)
->getSheetData();
var_dump($data);
$data = $excel->openFile('open_xlsx_get_data_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_CELLS|\Vtiful\Kernel\Excel::SKIP_EMPTY_ROW)
->getSheetData();
var_dump($data);
$data = $excel->openFile('open_xlsx_get_data_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_VALUE)
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_data_skip_empty.xlsx');
?>
--EXPECT--
array(3) {
[0]=>
array(1) {
[1]=>
string(4) "Cost"
}
[1]=>
array(0) {
}
[2]=>
array(1) {
[0]=>
string(5) "viest"
}
}
array(2) {
[0]=>
array(2) {
[0]=>
string(0) ""
[1]=>
string(4) "Cost"
}
[1]=>
array(2) {
[0]=>
string(5) "viest"
[1]=>
string(0) ""
}
}
array(2) {
[0]=>
array(1) {
[1]=>
string(4) "Cost"
}
[1]=>
array(1) {
[0]=>
string(5) "viest"
}
}
array(3) {
[0]=>
array(1) {
[1]=>
string(4) "Cost"
}
[1]=>
array(0) {
}
[2]=>
array(1) {
[0]=>
string(5) "viest"
}
}

View File

@ -0,0 +1,59 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests/xlsx'];
$excel = new \Vtiful\Kernel\Excel($config);
$data = $excel->openFile('hidden_row.xlsx')
->openSheet('Sheet1')
->getSheetData();
var_dump($data);
$data = $excel->openFile('hidden_row.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_HIDDEN_ROW|\Vtiful\Kernel\Excel::SKIP_EMPTY_ROW)
->getSheetData();
var_dump($data);
?>
--EXPECT--
array(4) {
[0]=>
array(1) {
[0]=>
string(4) "name"
}
[1]=>
array(1) {
[0]=>
string(8) "ZhangSan"
}
[2]=>
array(1) {
[0]=>
string(4) "LiSi"
}
[3]=>
array(1) {
[0]=>
string(6) "WangWu"
}
}
array(2) {
[0]=>
array(1) {
[0]=>
string(4) "name"
}
[1]=>
array(1) {
[0]=>
string(6) "WangWu"
}
}

View File

@ -0,0 +1,45 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_data_skip_rows.xlsx', 'TestSheet1')
->header(['Item', 'Cost'])
->data([
['Item_1', 'Cost_1', 10, 10.9999995],
['Item_2', 'Cost_2', 10, 10.9999995],
['Item_3', 'Cost_3', 10, 10.9999995],
])
->output();
$data = $excel->openFile('open_xlsx_get_data_skip_rows.xlsx')
->openSheet()
->setSkipRows(3)
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_data_skip_rows.xlsx');
?>
--EXPECT--
array(1) {
[0]=>
array(4) {
[0]=>
string(6) "Item_3"
[1]=>
string(6) "Cost_3"
[2]=>
int(10)
[3]=>
float(10.9999995)
}
}

View File

@ -0,0 +1,55 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_data_with_set_type.xlsx')
->header(['Name', 'Age', 'Date'])
->data([
['Viest', 24]
])
->insertDate(1, 2, 1568877706)
->output();
$data = $excel->openFile('open_xlsx_get_data_with_set_type.xlsx')
->openSheet()
->setType([
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_TIMESTAMP,
])
->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_data_with_set_type.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
array(3) {
[0]=>
string(4) "Name"
[1]=>
string(3) "Age"
[2]=>
string(4) "Date"
}
[1]=>
array(3) {
[0]=>
string(5) "Viest"
[1]=>
string(2) "24"
[2]=>
int(1568877706)
}
}

View File

@ -0,0 +1,27 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_get_sheet_not_found_data.xlsx')
->header(['Item', 'Cost'])
->output();
$data = $excel->openFile('open_xlsx_get_sheet_not_found_data.xlsx')
->openSheet('not_found')->getSheetData();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_get_sheet_not_found_data.xlsx');
?>
--EXPECT--
array(0) {
}

View File

@ -0,0 +1,107 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_global_data_type.xlsx')
->header(['Item', 'Cost', 'Int', 'Double'])
->data([
['Item_1', 'Cost_1', 10, 10.9999995],
])
->output();
$excel->openFile('open_xlsx_global_data_type.xlsx')
->setGlobalType(\Vtiful\Kernel\Excel::TYPE_DOUBLE)
->nextCellCallback(function ($row, $cell, $data) {
echo 'cell:' . $cell . ', row:' . $row .', data type:' . gettype($data) . PHP_EOL;
});
echo '----------------' . PHP_EOL;
$data = $excel->openFile('open_xlsx_global_data_type.xlsx')
->openSheet()
->setGlobalType(\Vtiful\Kernel\Excel::TYPE_STRING)
->getSheetData();
var_dump($data);
$excel->openFile('open_xlsx_global_data_type.xlsx')
->openSheet()
->setGlobalType(\Vtiful\Kernel\Excel::TYPE_INT);
echo '----------------' . PHP_EOL;
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_global_data_type.xlsx');
?>
--EXPECT--
cell:0, row:0, data type:string
cell:1, row:0, data type:string
cell:2, row:0, data type:string
cell:3, row:0, data type:string
cell:3, row:0, data type:string
cell:0, row:1, data type:string
cell:1, row:1, data type:string
cell:2, row:1, data type:double
cell:3, row:1, data type:double
cell:3, row:1, data type:string
----------------
array(2) {
[0]=>
array(4) {
[0]=>
string(4) "Item"
[1]=>
string(4) "Cost"
[2]=>
string(3) "Int"
[3]=>
string(6) "Double"
}
[1]=>
array(4) {
[0]=>
string(6) "Item_1"
[1]=>
string(6) "Cost_1"
[2]=>
string(2) "10"
[3]=>
string(10) "10.9999995"
}
}
----------------
array(4) {
[0]=>
string(4) "Item"
[1]=>
string(4) "Cost"
[2]=>
string(3) "Int"
[3]=>
string(6) "Double"
}
array(4) {
[0]=>
string(6) "Item_1"
[1]=>
string(6) "Cost_1"
[2]=>
int(10)
[3]=>
int(10)
}
NULL
NULL

View File

@ -0,0 +1,33 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_cell_callback.xlsx')
->header(['Item', 'Cost'])
->data([
['Item_1', 'Cost_1'],
])
->output();
$excel->openFile('open_xlsx_next_cell_callback.xlsx')->nextCellCallback(function ($row, $cell, $data) {
echo 'cell:' . $cell . ', row:' . $row . ', value:' . $data . PHP_EOL;
});
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_cell_callback.xlsx');
?>
--EXPECT--
cell:0, row:0, value:Item
cell:1, row:0, value:Cost
cell:1, row:0, value:XLSX_ROW_END
cell:0, row:1, value:Item_1
cell:1, row:1, value:Cost_1
cell:1, row:1, value:XLSX_ROW_END

View File

@ -0,0 +1,48 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_cell_callback_with_data_type.xlsx')
->header(['Item', 'Cost', 'Int', 'Double', 'Date'])
->data([
['Item_1', 'Cost_1', 10, 10.9999995],
])
->insertDate(1, 4, 1568904314)
->output();
$excel->openFile('open_xlsx_next_cell_callback_with_data_type.xlsx')
->setType([
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_INT,
\Vtiful\Kernel\Excel::TYPE_DOUBLE,
\Vtiful\Kernel\Excel::TYPE_TIMESTAMP,
])
->nextCellCallback(function ($row, $cell, $data) {
echo 'cell:' . $cell . ', row:' . $row .', data type:' . gettype($data) . PHP_EOL;
});
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_cell_callback_with_data_type.xlsx');
?>
--EXPECT--
cell:0, row:0, data type:string
cell:1, row:0, data type:string
cell:2, row:0, data type:string
cell:3, row:0, data type:string
cell:4, row:0, data type:string
cell:4, row:0, data type:string
cell:0, row:1, data type:string
cell:1, row:1, data type:string
cell:2, row:1, data type:integer
cell:3, row:1, data type:double
cell:4, row:1, data type:integer
cell:4, row:1, data type:string

View File

@ -0,0 +1,51 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_row.xlsx')
->header(['Item', 'Cost'])
->data([
['Item_1', 'Cost_1'],
])
->output();
$excel->openFile('open_xlsx_next_row.xlsx')
->openSheet();
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
var_dump($excel->nextRow());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
string(4) "Item"
[1]=>
string(4) "Cost"
}
array(2) {
[0]=>
string(6) "Item_1"
[1]=>
string(6) "Cost_1"
}
NULL
NULL
NULL
NULL
NULL

View File

@ -0,0 +1,84 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_row_skip_empty.xlsx')
->header(['', 'Cost'])
->data([
[],
['viest', ''],
])
->output();
echo 'skip cells' . PHP_EOL;
$data = $excel->openFile('open_xlsx_next_row_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_CELLS);
while (is_array($data = $excel->nextRow())) {
var_dump($data);
}
echo 'skip row' . PHP_EOL;
$data = $excel->openFile('open_xlsx_next_row_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_ROW);
while (is_array($data = $excel->nextRow())) {
var_dump($data);
}
echo 'skip cells & row' . PHP_EOL;
$data = $excel->openFile('open_xlsx_next_row_skip_empty.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_CELLS | \Vtiful\Kernel\Excel::SKIP_EMPTY_ROW);
while (is_array($data = $excel->nextRow())) {
var_dump($data);
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_skip_empty.xlsx');
?>
--EXPECT--
skip cells
array(1) {
[1]=>
string(4) "Cost"
}
array(0) {
}
array(1) {
[0]=>
string(5) "viest"
}
skip row
array(2) {
[0]=>
string(0) ""
[1]=>
string(4) "Cost"
}
array(2) {
[0]=>
string(5) "viest"
[1]=>
string(0) ""
}
skip cells & row
array(1) {
[1]=>
string(4) "Cost"
}
array(1) {
[0]=>
string(5) "viest"
}

View File

@ -0,0 +1,43 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_row_skip_rows.xlsx', 'TestSheet1')
->header(['Item', 'Cost'])
->data([
['Item_1', 'Cost_1', 10, 10.9999995],
['Item_2', 'Cost_2', 10, 10.9999995],
['Item_3', 'Cost_3', 10, 10.9999995],
])
->output();
$excel->openFile('open_xlsx_next_row_skip_rows.xlsx')
->openSheet()
->setSkipRows(3);
while (is_array($data = $excel->nextRow())) {
var_dump($data);
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_skip_rows.xlsx');
?>
--EXPECT--
array(4) {
[0]=>
string(6) "Item_3"
[1]=>
string(6) "Cost_3"
[2]=>
int(10)
[3]=>
float(10.9999995)
}

View File

@ -0,0 +1,49 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = [
'path' => './tests',
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('open_xlsx_next_row_with_data_type_date.xlsx');
$filePath = $fileObject->header(['date'])
->insertDate(1, 0, 1568389354, 'mmm d yyyy hh:mm AM/PM')
->output();
$fileObject->openFile('open_xlsx_next_row_with_data_type_date.xlsx')
->openSheet();
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING])); // Header
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
var_dump($fileObject->nextRow([\Vtiful\Kernel\Excel::TYPE_TIMESTAMP]));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_with_data_type_date.xlsx');
?>
--EXPECT--
array(1) {
[0]=>
string(4) "date"
}
array(1) {
[0]=>
int(1568389354)
}
NULL
NULL
NULL
NULL
NULL

View File

@ -0,0 +1,56 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_row_with_data_type_date_array_index.xlsx')
->header(['', 'Cost'])
->data([
[],
['viest', ''],
])
->insertDate(2, 4, 1568818881)
->output();
$data = $excel->openFile('open_xlsx_next_row_with_data_type_date_array_index.xlsx')
->openSheet('Sheet1');
while (is_array($data = $excel->nextRow([4 => \Vtiful\Kernel\Excel::TYPE_TIMESTAMP]))) {
var_dump($data);
}
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_with_data_type_date_array_index.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
string(0) ""
[1]=>
string(4) "Cost"
}
array(2) {
[0]=>
string(0) ""
[1]=>
string(0) ""
}
array(5) {
[0]=>
string(5) "viest"
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(0) ""
[4]=>
int(1568818881)
}

View File

@ -0,0 +1,51 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_next_row_with_data_type_string.xlsx')
->header(['Item', 'Cost'])
->data([
['Item_1', 'Cost_1'],
])
->output();
$excel->openFile('open_xlsx_next_row_with_data_type_string.xlsx')
->openSheet();
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_with_data_type_string.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
string(4) "Item"
[1]=>
string(4) "Cost"
}
array(2) {
[0]=>
string(6) "Item_1"
[1]=>
string(6) "Cost_1"
}
NULL
NULL
NULL
NULL
NULL

View File

@ -0,0 +1,52 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('open_xlsx_next_row_with_set_type.xlsx');
$filePath = $fileObject->data([
[1, 'Test']
])
->insertDate(1, 2, 1568389354, 'mmm d yyyy hh:mm AM/PM')
->output();
$fileObject->openFile('open_xlsx_next_row_with_set_type.xlsx')
->openSheet()
->setType([
\Vtiful\Kernel\Excel::TYPE_INT,
\Vtiful\Kernel\Excel::TYPE_STRING,
\Vtiful\Kernel\Excel::TYPE_TIMESTAMP,
]);
var_dump($fileObject->nextRow()); // Header
var_dump($fileObject->nextRow());
var_dump($fileObject->nextRow());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_next_row_with_set_type.xlsx');
?>
--EXPECT--
array(2) {
[0]=>
int(1)
[1]=>
string(4) "Test"
}
array(3) {
[0]=>
NULL
[1]=>
string(0) ""
[2]=>
int(1568389354)
}
NULL

View File

@ -0,0 +1,35 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_sheet.xlsx')
->header(['Item', 'Cost'])
->output();
$data = $excel->openFile('open_xlsx_sheet.xlsx')->openSheet();
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_sheet.xlsx');
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(28) "./tests/open_xlsx_sheet.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

View File

@ -0,0 +1,36 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_sheet_flag.xlsx')
->header(['Item', 'Cost'])
->output();
$data = $excel->openFile('open_xlsx_sheet_flag.xlsx')
->openSheet('Sheet1', \Vtiful\Kernel\Excel::SKIP_EMPTY_CELLS);
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_sheet_flag.xlsx');
?>
--EXPECT--
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(33) "./tests/open_xlsx_sheet_flag.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

View File

@ -0,0 +1,30 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php
require __DIR__ . '/include/skipif.inc';
skip_disable_reader();
?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('open_xlsx_sheet_list.xlsx', 'TestSheet1')
->header(['Item', 'Cost'])
->output();
$sheetList = $excel->openFile('open_xlsx_sheet_list.xlsx')->sheetList();
var_dump(is_array($sheetList));
var_dump($sheetList);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/open_xlsx_sheet_list.xlsx');
?>
--EXPECT--
bool(true)
array(1) {
[0]=>
string(10) "TestSheet1"
}

30
tests/paper.phpt Normal file
View File

@ -0,0 +1,30 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('paper.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->setPaper(\Vtiful\Kernel\Excel::PAPER_A3)
->setLandscape()
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/paper.xlsx');
?>
--EXPECT--
string(18) "./tests/paper.xlsx"

86
tests/printed.phpt Normal file
View File

@ -0,0 +1,86 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
try {
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->setPortrait();
} catch (\Exception $exception) {
var_dump($exception->getCode());
var_dump($exception->getMessage());
}
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('printed_portrait.xlsx', 'sheet1')
->setPortrait()
->output();
var_dump($excel);
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('printed_landscape.xlsx', 'sheet1')
->setLandscape()
->output();
var_dump($excel);
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('printed_scale.xlsx', 'sheet1')
->setPrintScale(180)
->output();
var_dump($excel);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/printed_portrait.xlsx');
@unlink(__DIR__ . '/printed_landscape.xlsx');
@unlink(__DIR__ . '/printed_scale.xlsx');
?>
--EXPECT--
int(130)
string(51) "Please create a file first, use the filename method"
object(Vtiful\Kernel\Excel)#3 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(29) "./tests/printed_portrait.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}
object(Vtiful\Kernel\Excel)#1 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(30) "./tests/printed_landscape.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}
object(Vtiful\Kernel\Excel)#3 (3) {
["config":"Vtiful\Kernel\Excel":private]=>
array(1) {
["path"]=>
string(7) "./tests"
}
["fileName":"Vtiful\Kernel\Excel":private]=>
string(26) "./tests/printed_scale.xlsx"
["read_row_type":"Vtiful\Kernel\Excel":private]=>
NULL
}

29
tests/protection.phpt Normal file
View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('protection.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->protection()
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/protection.xlsx');
?>
--EXPECT--
string(23) "./tests/protection.xlsx"

View File

@ -0,0 +1,29 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = [
'path' => './tests'
];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName('protection_password.xlsx');
$filePath = $fileObject->header(['name', 'age'])
->data([
['viest', 21],
['wjx', 21]
])
->protection('password')
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/protection_password.xlsx');
?>
--EXPECT--
string(32) "./tests/protection_password.xlsx"

56
tests/rich_string.phpt Normal file
View File

@ -0,0 +1,56 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$fileObject = new \Vtiful\Kernel\Excel($config);
$fileObject = $fileObject->fileName("rich_string.xlsx")
->header(['rich string']);
$fileHandle = $fileObject->getHandle();
$format1 = new \Vtiful\Kernel\Format($fileHandle);
$colorRed = $format1->fontColor(\Vtiful\Kernel\Format::COLOR_GREEN)->toResource();
$format2 = new \Vtiful\Kernel\Format($fileHandle);
$colorOrange = $format2->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
$richStringOne = new \Vtiful\Kernel\RichString('red ', $colorRed);
$richStringTwo = new \Vtiful\Kernel\RichString('orange', $colorOrange);
$fileObject->insertRichText(1, 0, [
$richStringOne,
$richStringTwo
]);
$filePath = $fileObject->output();
$data = $fileObject->openFile('rich_string.xlsx')
->openSheet()
->getSheetData();
var_dump($filePath);
var_dump($data);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/rich_string.xlsx');
?>
--EXPECT--
string(24) "./tests/rich_string.xlsx"
array(2) {
[0]=>
array(1) {
[0]=>
string(11) "rich string"
}
[1]=>
array(1) {
[0]=>
string(10) "red orange"
}
}

28
tests/sheet_add.phpt Normal file
View File

@ -0,0 +1,28 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName("sheet_add.xlsx");
$fileObject->header(['name', 'age'])
->data([['viest', 21]]);
$fileObject->addSheet('twoSheet')
->header(['name', 'age'])
->data([['vikin', 22]]);
$filePath = $fileObject->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/sheet_add.xlsx');
?>
--EXPECT--
string(22) "./tests/sheet_add.xlsx"

35
tests/sheet_checkout.phpt Normal file
View File

@ -0,0 +1,35 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$fileObject = $excel->fileName("sheet_checkout.xlsx");
$fileObject->header(['name', 'age'])
->data([
['viest', 21],
['viest', 22],
['viest', 23],
]);
$fileObject->addSheet('twoSheet')
->header(['name', 'age'])
->data([['vikin', 22]]);
$fileObject->checkoutSheet('Sheet1')
->data([['sheet1']]);
$filePath = $fileObject->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/sheet_checkout.xlsx');
?>
--EXPECT--
string(27) "./tests/sheet_checkout.xlsx"

23
tests/show_comment.phpt Normal file
View File

@ -0,0 +1,23 @@
--TEST--
Check for vtiful presence
--SKIPIF--
<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
--FILE--
<?php
$config = ['path' => './tests'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('show_comment.xlsx')
->header(['Item', 'Cost'])
->insertComment(0,1,'comment')
->showComment()
->output();
var_dump($filePath);
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/show_comment.xlsx');
?>
--EXPECT--
string(25) "./tests/show_comment.xlsx"

Some files were not shown because too many files have changed in this diff Show More