繁体   English   中英

使用 PHP Excel 从 Excel 文件导入数据

[英]Importing data from Excel File using PHP Excel

我正在尝试从 excel 工作表中导入一些数据,但是我的一个变量(级别)不起作用。 我希望有人可以看看为什么这个不起作用,但事件和部门可以。

class CompetitionClass 
{
   public $event;
   public $division;
   public $level;

   function __construct(){

      $this->entryTable = array();
   }
}



$x++;
$compClass[$x] = new CompetitionClass();
$compClass[$x] -> event = htmlspecialchars((string)$objPHPExcel->getSheet($key)->getCell('F1')->getOldCalculatedValue());
$compClass[$x] -> division = htmlspecialchars((string)$objPHPExcel->getSheet($key)->getCell('H1')->getOldCalculatedValue());
$compClass[$x] -> level = htmlspecialchars((string)$objPHPExcel->getSheet($key)->getCell('F2')->getOldCalculatedValue());



foreach($compClass as $key => $value)
{
   if($value -> division == "MOD")
   {
       print(strtoupper($value -> event)."&nbsp;&nbsp;&nbsp; ".strtoupper($value -> level)."&nbsp;&nbsp;&nbsp; ".strtoupper($value -> division)."<BR/>");
   } 

}

我不得不更改我的 readCell function 以包括第 2 行而不仅仅是第 1 行。

这是我在更改之前所拥有的:

class MyReadFilter implements PHPExcel_Reader_IReadFilter
{
   public function readCell($column, $row, $worksheetName = '')
   {
      if (($row == 1 and in_array($column, range('F','H'))) or ($row >= 3 and $row <= 25 and in_array($column, range('G','N'))))
         { return true; }
      return false;
   }
}

这是更改后的:

class MyReadFilter implements PHPExcel_Reader_IReadFilter
{
   public function readCell($column, $row, $worksheetName = '')
   {
      if (($row >= 1 and $row <= 2 and in_array($column, range('F','H'))) or ($row >= 3 and $row <= 25 and in_array($column, range('G','N'))))
         { return true; }
      return false;
   }
}

所以将 $row == 1 更改为 $row >= 1 和 $row <= 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM