xlsx_to_csv_callback_custom_delimiter.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Check for vtiful presence
  3. --SKIPIF--
  4. <?php
  5. require __DIR__ . '/include/skipif.inc';
  6. skip_disable_reader();
  7. ?>
  8. --FILE--
  9. <?php
  10. $config = ['path' => './tests'];
  11. $excel = new \Vtiful\Kernel\Excel($config);
  12. $filePath = $excel->fileName('tutorial.xlsx', 'TestSheet1')
  13. ->header(['Item', 'Cost'])
  14. ->data([
  15. ['Item_1', 'Cost_1', 10, 10.9999995],
  16. ])
  17. ->output();
  18. $fp = fopen('./tests/file.csv', 'w');
  19. $csvResult = $excel->openFile('tutorial.xlsx')
  20. ->openSheet()
  21. ->putCSVCallback(function($row){
  22. return $row;
  23. }, $fp, ';');
  24. var_dump($csvResult);
  25. if (($csvHandler = fopen('./tests/file.csv', 'r')) === FALSE) {
  26. die('csv file open failure');
  27. }
  28. while (($data = fgetcsv($csvHandler, 1000, ';')) !== FALSE) {
  29. var_dump($data);
  30. }
  31. ?>
  32. --CLEAN--
  33. <?php
  34. @unlink(__DIR__ . '/tutorial.xlsx');
  35. @unlink(__DIR__ . '/file.csv');
  36. ?>
  37. --EXPECT--
  38. bool(true)
  39. array(2) {
  40. [0]=>
  41. string(4) "Item"
  42. [1]=>
  43. string(4) "Cost"
  44. }
  45. array(4) {
  46. [0]=>
  47. string(6) "Item_1"
  48. [1]=>
  49. string(6) "Cost_1"
  50. [2]=>
  51. string(2) "10"
  52. [3]=>
  53. string(10) "10.9999995"
  54. }