代码拉取完成,页面将自动刷新
<?php
require_once "./PHPExcel/PHPExcel/IOFactory.php";
function excelToArray($filename,$row = false)
{
$objPHPExcelReader = PHPExcel_IOFactory::load($filename);
$reader = $objPHPExcelReader->getWorksheetIterator();
$new_arr = [];
foreach ($reader as $sheet) {
$content = $sheet->getRowIterator();
$res_arr = array();
foreach ($content as $key => $items) {
$rows = $items->getRowIndex();
$columns = $items->getCellIterator();
$row_arr = array();
if (!$row) {
if ($rows < 1) {
continue;
}
} else {
if ($rows < 2) {
continue;
}
}
foreach ($columns as $head => $cell) {
$data = $cell->getValue();
$row_arr[] = $data;
}
$res_arr[] = $row_arr;
}
$new_arr[] = $res_arr;
}
return $new_arr;
}
$filename = "./伊婉.xlsx";
$ret = excelToArray($filename);
if ($ret) {
$num_sheet = count($ret);
$n = 1;
foreach ($ret as $k => $v) {
$m = array_shift($v);
$num = count($m);
foreach ($v as $k1 => $v1) {
for ($i = 0; $i < $num; $i++) {
$arr[$m[$i]] = $v1[$i];
}
$new_arr1[] = $arr;
}
$new_arr2["Sheet".$n] = $new_arr1;
$n++;
}
echo json_encode($new_arr2);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。