test.php 2.3 KB

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