shish 1 year ago
parent
commit
37cc10e5df
1 changed files with 7 additions and 13 deletions
  1. 7 13
      app-ghs/controllers/CsController.php

+ 7 - 13
app-ghs/controllers/CsController.php

@@ -51,22 +51,16 @@ class CsController extends BaseController
         $currentDirectory = getcwd();
 
         require_once($phpExcelFile . 'Classes/PHPExcel/IOFactory.php');
-        $objPHPExcel = \PHPExcel_IOFactory::load($currentDirectory . "/123.xlsx");
+        $spreadsheet = \PHPExcel_IOFactory::load($currentDirectory . "/123.xlsx");
 
         //print_r($objPHPExcel->getActiveSheet()->toArray());
 
-        echo 'Custom Properties:';
-        $customProperties = $objPHPExcel->getProperties()->getCustomProperties();
-        foreach($customProperties as $customProperty) {
-            $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
-            $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customProperty);
-            echo '    ' , $customProperty , ' - (' , $propertyType , ') - ';
-            if ($propertyType == \PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE) {
-                echo date('d-M-Y H:i:s',$propertyValue);
-            } elseif ($propertyType == \PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) {
-                echo $propertyValue;
-            } else {
-                echo $propertyValue;
+        foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) {
+            foreach ($row->getCellIterator() as $cell) {
+                if (!$cell->getValue()) { // 跳过空白单元格
+                    continue;
+                }
+                echo 'Cell ' . $cell->getColumn() . $cell->getRow() . ' = ' . $cell->getValue() . '<br />';
             }
         }