Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Catchable fatal error: Object of class BoxSpoutReaderXLSXReader could not
  2. be converted to string in C:xampphtdocssubir_exceluploadExcel.php on line
  3. 62
  4.  
  5. <?php
  6.  
  7. $servername = "localhost";
  8. $username = "root";
  9. $password = "";
  10. $dbname = "estudiantes_tuto";
  11.  
  12. $conn = mysqli_connect($servername, $username, $password, $dbname);
  13.  
  14.  
  15. if (!$conn) {
  16. die("Connection failed: " . mysqli_connect_error());
  17. }
  18.  
  19. echo "conectado";
  20.  
  21. use BoxSpoutReaderReaderFactory;
  22. use BoxSpoutCommonType;
  23.  
  24. // Incluir Spout library
  25. require_once 'src/Spout/Autoloader/autoload.php';
  26.  
  27.  
  28. if (!empty($_FILES['file']['name'])) {
  29.  
  30.  
  31. $pathinfo = pathinfo($_FILES["file"]["name"]);
  32.  
  33.  
  34. if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
  35. && $_FILES['file']['size'] > 0 ) {
  36.  
  37. // Temporary file name
  38. $inputFileName = $_FILES['file']['tmp_name'];
  39.  
  40. // Read excel file by using ReadFactory object.
  41. $reader = ReaderFactory::create(Type::XLSX);
  42.  
  43. // Open file
  44. $reader->open($inputFileName);
  45. $count = 1;
  46.  
  47. // Number of sheet in excel file
  48. foreach ($reader->getSheetIterator() as $sheet) {
  49.  
  50. // Number of Rows in Excel sheet
  51. foreach ($sheet->getRowIterator() as $row) {
  52.  
  53. // It reads data after header. In the my excel sheet,
  54. // header is in the first row.
  55. if ($count > 1) {
  56.  
  57. // Data of excel sheet
  58. $data['nombre_es'] = $row[0];
  59. $data['apellido_pa'] = $row[1];
  60. $data['apellido_ma'] = $row[2];
  61.  
  62.  
  63.  
  64.  
  65. $sql="INSERT INTO estudiantes VALUES('$reader')";
  66. $resultado=mysqli_query($this->conn,$sql);
  67.  
  68.  
  69. //print_r($data);
  70.  
  71. }
  72. $count++;
  73. }
  74. }
  75.  
  76. // Close excel file
  77. $reader->close();
  78.  
  79. } else {
  80.  
  81. echo "Please Select Valid Excel File";
  82. }
  83.  
  84. } else {
  85.  
  86. echo "Please Select Excel File";
  87.  
  88. }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement