2017-05-03 5 views
0
foreach($objPHPExcel->getWorksheetIterator() as $worksheet) 
     { 
      echo '<table border ="1px" width ="50%" float:left overflow:auto>' . "\n"; 
      foreach ($objWorksheet->getRowIterator() as $row) { 
       echo '<tr>' . "\n"; 
       $cellIterator = $row->getCellIterator(); 
       $cellIterator->setIterateOnlyExistingCells(false); 
       $y =0; 
       foreach ($cellIterator as $cell) { 
        $promptData[$x][$y] = $cell->getValue(); 
        $cellIndex = $cell->getCoordinate(); 
        $promptData[$x][$y]['Index'] = $cellIndex; 
        echo '<td>' . $promptData[$x][$y] . '</td>' .'<td>' . $cell->getCalculatedValue() . '</td>' . "\n"; 
        $y++; 
       } 
       $x++; 
       echo '</tr>' . "\n"; 
      } 
      echo '</table>' . "\n"; 
     } 

I Index der Zelle in der 2D-Array speichern möchte ich bin mit $ promptData [$ x] [$ y] [ 'Index'] = $ ZellIndex; Aber es funktioniert nicht, kann jemand helfen.hinzufügen Schlüsselwert 2d Array mit foreach-Schleife in PHP

+0

Ich bekomme Fehler als Array zu String-Konvertierung in $ promptData [$ x] [$ y] ['Index'] = $ CellIndex; –

+0

Als der Fehler sagen Sie versuchen, print_r seine Struktur zu kennen – Osama

Antwort

0

Das Problem ist sind Sie $prompt[$x][$y] zunächst als Wert den Wert definiert, dann als Array:

$promptData[$x][$y] = $cell->getValue(); 
$cellIndex = $cell->getCoordinate(); 
$promptData[$x][$y]['Index'] = $cellIndex; 
echo '<td>' . $promptData[$x][$y] . '</td>' .'<td>' . $cell->getCalculatedValue() . '</td>' . "\n"; 

Versuchen Sie, den Wert zu einem Array-Elemente für die Zelle zuweisen, dann eher genau das Array-Elements Echo als das gesamte Array:

$promptData[$x][$y] = [ 
    'Value' => $cell->getValue(), 
    'Index' => $cell->getCoordinate() 
]; 
echo '<td>' . $promptData[$x][$y]['Value'] . '</td>' .'<td>' . $cell->getCalculatedValue() . '</td>' . "\n"; 
+0

Ich bekomme einen Fehler in Ihrem Vorschlag reagrding => –

+0

Woops, hatte einen Tippfehler, hatte ein '.' Anstelle von '' ''. Versuchen Sie es jetzt –

+0

Ich möchte noch eine Frage stellen, wenn ich diese Werte abrufen möchte, also wie kann ich das tun. –