Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 读取xlsx转换为数组_Php_Arrays_Excel - Fatal编程技术网

Php 读取xlsx转换为数组

Php 读取xlsx转换为数组,php,arrays,excel,Php,Arrays,Excel,是否可以使用PHP读取以下xlsx文件,然后将其转换为如下数组 我想我需要一个支持坐标的Excel类 array("Date" => "05-jan", "Room" => "205", "Activity" => ""); array("Date" => "05-jan", "Room" => "209", "Activity" => "Test1"); array("Date" => "06-jan", "Room" => "205", "A

是否可以使用PHP读取以下xlsx文件,然后将其转换为如下数组

我想我需要一个支持坐标的Excel类

array("Date" => "05-jan", "Room" => "205", "Activity" => "");
array("Date" => "05-jan", "Room" => "209", "Activity" => "Test1");

array("Date" => "06-jan", "Room" => "205", "Activity" => "");
array("Date" => "06-jan", "Room" => "205", "Activity" => "Test2");

array("Date" => "07-jan", "Room" => "205", "Activity" => "");
array("Date" => "07-jan", "Room" => "209-pc", "Activity" => "Test3");

array("Date" => "08-jan", "Room" => "205", "Activity" => "");
array("Date" => "08-jan", "Room" => "209-pc", "Activity" => "");

array("Date" => "09-jan", "Room" => "205", "Activity" => "");
array("Date" => "09-jan", "Room" => "209-pc", "Activity" => "");

通过这段代码,我得到了内容

输出

Array ( [0] => [1] => [2] => 2 - 2015 [3] => [4] => [5] => [6] => )
Array ( [0] => [1] => [2] => 5-Jan [3] => 6-Jan [4] => 7-Jan [5] => 8-Jan[6] => 9-Jan ) 
  Array ( [0] => [1] => [2] => Monday [3] => Tuesday [4] => Wednesday [5] => Thursday [6] => Friday ) 
   Array ( [0] => 205 [1] => Fo. [2] => [3] => [4] => [5] => [6] => ) 
  Array ( [0] => 24+ [1] => Ef. [2] => [3] => [4] => [5] => [6] => ) 
   Array ( [0] => 209-pc [1] => Fo. [2] => Test1 [3] => Test2 [4] => Test3 [5] => [6] => ) 
Array ( [0] => 24 [1] => Ef. [2] => [3] => [4] => [5] => [6] => ) 
你可以用


这将根据需要将excel数据存储为数组。非常方便。

我当前的电子表格阅读器版本也有问题

您可以通过更改SpreadsheetReader_XLSX.php文件中的Sheets()方法进行修复

      public function Sheets() {

      if ($this -> Sheets === false) {
          $this -> Sheets = array();
          foreach ($this -> WorkbookXML -> sheets -> sheet as $Index => $Sheet) {
              $AttributesWithPrefix = $Sheet -> attributes('r', true);
              $Attributes = $Sheet -> attributes();
              $rId = 0;
              $sheetId = 0;
              foreach ($AttributesWithPrefix as $Name => $Value) {
                  if ($Name == 'id') {
                     $rId = (int)str_replace('rId', '', (string)$Value);
                     break;
                  }
              }

              foreach ($Attributes as $Name => $Value) {
                  if ($Name == 'sheetId') {
                      $sheetId = (int)$Value;
                      break;
                  }
              }
              $this -> Sheets[min($rId, $sheetId)] = (string)$Sheet['name'];
          }
          ksort($this -> Sheets);
      } 
      return array_values($this -> Sheets);
  }

您是否尝试过查看任何现有的PHP库来读取Excel文件,例如?您可以尝试这样的方法:我可以从Excel文件中获取所有数据。但是我并没有把每个单元格都放在一个变量中,所以请显示到目前为止你得到的代码,以及它给你的数组
和它给你的数组

      public function Sheets() {

      if ($this -> Sheets === false) {
          $this -> Sheets = array();
          foreach ($this -> WorkbookXML -> sheets -> sheet as $Index => $Sheet) {
              $AttributesWithPrefix = $Sheet -> attributes('r', true);
              $Attributes = $Sheet -> attributes();
              $rId = 0;
              $sheetId = 0;
              foreach ($AttributesWithPrefix as $Name => $Value) {
                  if ($Name == 'id') {
                     $rId = (int)str_replace('rId', '', (string)$Value);
                     break;
                  }
              }

              foreach ($Attributes as $Name => $Value) {
                  if ($Name == 'sheetId') {
                      $sheetId = (int)$Value;
                      break;
                  }
              }
              $this -> Sheets[min($rId, $sheetId)] = (string)$Sheet['name'];
          }
          ksort($this -> Sheets);
      } 
      return array_values($this -> Sheets);
  }