这是我的代码我做了什么......但这里的场景有点不同,这里的输入是excel文件,而输出是'key'=>'value'对中的数组数组(就像你的情况一样反之亦然)这不是一个解决方案,但它可能会帮助你继续前进。
<?php
include './PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load('campaign.xlsx');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$highestColumn = $worksheet->getHighestDataColumn();
//Getting highest column with data
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
//Getting highest row with data
$highestRow = $worksheet->getHighestRow();
$header = [];
//For saving all heading from Excel file.
for( $i = 0 ; $i <= $highestColumnIndex ; $i++)
{
$cell = $worksheet->getCellByColumnAndRow($i,1);
$val = $cell->getValue();
$header[] = $val;
}
$completeArray = [];
$value = [];
//For saving header and value pairs in a array
for ($row = 2; $row <= $highestRow; ++ $row) {
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
$value[$header[$col]] = $val;
}
//Inserting that array...
$completeArray[] = $value;
}
}
echo '<pre>';
print_r($completeArray);
echo '</pre>';
因此,在您的情况下,您可以使用我的示例中的所有 get 方法,例如 getCellByColumnAndRow
setCellValueByColumnAndRow($column, $row, $value);
您也可以在此处获得教程的帮助
备忘单在这里