Skip to content

Magento 2: How to import and export simple_ANSI.xlsx file

I have created the function to import the data through CSV file format, but now I wanted to import the data through simple_ANSI.xlsx file.

My Controller:

public function execute()
      {
        /** @get csv file */
        $filename = $_FILES["prod_massupload"]["tmp_name"];
        $items = $this->_items->create();
        $row = 1;
         if (($handle = fopen($filename, "r")) !== FALSE) {
              fgetcsv($handle);
              /** @loop product data */
                while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

                        $num = count($data);
                        $row++;
                        /** @getSku return:array */
                         $product = $data[0];;

                        /** @getProduct: qty */
                        $stock = $data[1];  

                        /** @getProduct: price */
                        $price = $data[2]; 
                      }
                 } 
             }

I can not find the proper solution to import the ANSI.xlsx file anywhere in the Magento 2.