Leff7's avatar
Level 4

Reading xlsx file

I am trying for the first time to implement reading from a xlsx file functionality. From the examples I could find I have come up with something like this:

$path = base_path('public/uploads/' .$file->getClientOriginalName());
$handle = fopen($path, "r");

while (($data = fgets($handle, 10000)) !== FALSE) {
   $line = explode(';',$data);

   $mall = $line[5];
   $store = $line[4];
   $price =  $line[6];
   $visitors = $line[3];

The xlsx file has 7 columns and more than 2000 rows, but I get:

Undefined offset: 5
0 likes
2 replies
tykus's avatar

Doubtful that anything you would read directly from an xlsx file would be useful in the way you describe because the xlsx format is compressed format containing XML documents, rather than CSV which is just your data

You would be wise to consider a library that implements PHP Excel, such as Maatwebsite's package for Laravel

1 like

Please or to participate in this conversation.