1 Star 1 Fork 0

Sam.Ju/excel转json

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
export_excel.php 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
jukunlong 提交于 2019-12-17 15:04 . dev
<?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);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/oschina052/excel_to_json.git
git@gitee.com:oschina052/excel_to_json.git
oschina052
excel_to_json
excel转json
master

搜索帮助