forked from nuovo/spreadsheet-reader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
100 lines (84 loc) · 2.31 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* XLS parsing uses php-excel-reader from http://code.google.com/p/php-excel-reader/
*/
header('Content-Type: text/plain');
if (isset($argv[1]))
{
$Filepath = $argv[1];
}
elseif (isset($_GET['File']))
{
$Filepath = $_GET['File'];
}
else
{
if (php_sapi_name() == 'cli')
{
echo 'Please specify filename as the first argument'.PHP_EOL;
}
else
{
echo 'Please specify filename as a HTTP GET parameter "File", e.g., "/test.php?File=test.xlsx"';
}
exit;
}
// Excel reader from http://code.google.com/p/php-excel-reader/
require('php-excel-reader/excel_reader2.php');
require('SpreadsheetReader.php');
date_default_timezone_set('UTC');
$StartMem = memory_get_usage();
echo '---------------------------------'.PHP_EOL;
echo 'Starting memory: '.$StartMem.PHP_EOL;
echo '---------------------------------'.PHP_EOL;
try
{
$Spreadsheet = new SpreadsheetReader($Filepath);
$BaseMem = memory_get_usage();
$Sheets = $Spreadsheet -> Sheets();
echo '---------------------------------'.PHP_EOL;
echo 'Spreadsheets:'.PHP_EOL;
print_r($Sheets);
echo '---------------------------------'.PHP_EOL;
echo '---------------------------------'.PHP_EOL;
foreach ($Sheets as $Index => $Name)
{
echo '---------------------------------'.PHP_EOL;
echo '*** Sheet '.$Name.' ***'.PHP_EOL;
echo '---------------------------------'.PHP_EOL;
$Time = microtime(true);
$Spreadsheet -> ChangeSheet($Index);
foreach ($Spreadsheet as $Key => $Row)
{
echo $Key.': ';
if ($Row)
{
print_r($Row);
}
else
{
var_dump($Row);
}
$CurrentMem = memory_get_usage();
echo 'Memory: '.($CurrentMem - $BaseMem).' current, '.$CurrentMem.' base'.PHP_EOL;
echo '---------------------------------'.PHP_EOL;
if ($Key && ($Key % 500 == 0))
{
echo '---------------------------------'.PHP_EOL;
echo 'Time: '.(microtime(true) - $Time);
echo '---------------------------------'.PHP_EOL;
}
}
echo PHP_EOL.'---------------------------------'.PHP_EOL;
echo 'Time: '.(microtime(true) - $Time);
echo PHP_EOL;
echo '---------------------------------'.PHP_EOL;
echo '*** End of sheet '.$Name.' ***'.PHP_EOL;
echo '---------------------------------'.PHP_EOL;
}
}
catch (Exception $E)
{
echo $E -> getMessage();
}
?>