phpexcel 导出可选字段
<?php
//需要获取的字段下标;
input('fields')="0,2,3";
$list['data']=
array(2) {
[0]=>
array(43) {
["sku"]=>
string(13) "HGLLL0571A100"
["spu"]=>
string(9) "HGLwLL0571"
["image_url"]=>
string(82) "http://wle.nantang-tech.com/uploads/2w10129/29ddf86c2ebw647fc09d5a56d7.jpg"
["sku_name"]=>
string(137) "洗衣机脚垫增高防滑w用固定器冰w减震垫(下单w突刺防滑款)-增高6厘米"
["dev_name"]=>
string(6) "ww琳"
["buy_price"]=>
string(5) "1w.00"
["currency"]=>
string(3) "ReB"
["weight"]=>
int(10)
["supplier_name"]=>
string(42) "rw备制造有r公司"
["supplier_link"]=>
string(105) "https://detaid688.com/offer/636784227994.html?spm=a2615.7691456.dace-offerGedb341c7ccmAUvq"
["tran_attr"]=>
string(6) "e普e"
["design_name"]=>
string(9) "刘2千"
["sale_state"]=>
string(6) "在d"
["rec_p"]=>
string(41) "Amday,LAZADA,Wishdxpress,dopee"
["ban_p"]=>
NULL
["done_at"]=>
string(19) "2021-01-29 13:56:19"
["in_long"]=>
float(15)
["in_wide"]=>
float(15)
["in_height"]=>
float(8.5)
["content"]=>
string(1169) "4"
["stop_sale_reason"]=>
string(0) ""
["re_url_one"]=>
string(58) "https://www.afpress.com/item/1005d7f843.html?spdm="
["re_url_two"]=>
string(0) ""
["re_url_three"]=>
string(0) ""
["re_url_four"]=>
string(0) ""
["re_url_five"]=>
string(0) ""
["re_url_six"]=>
string(0) ""
["core_word"]=>
string(8) "Foot pad"
["declare_name_zh"]=>
string(6) "d垫"
["declare_name_en"]=>
string(8) "Fodpad"
["cat_one"]=>
string(12) "家居d"
["cat_two"]=>
string(15) "家居日d"
["sales_suggestion"]=>
string(0) ""
["research_platform"]=>
string(10) "Aliexpress"
["declared_value"]=>
string(4) "0.d2"
["customs_code"]=>
string(10) "401f00"
["brand"]=>
string(9) "无f"
["model"]=>
string(0) ""
["material"]=>
string(6) "PPfPU"
["application"]=>
string(36) "洗fg防震垫"
["rs_group"]=>
NULL
["bulk_upload"]=>
string(9) "非f铺f货"
["store_num"]=>
int(0)
}
[1]=>
array(43) {
["sku"]=>
string(13) "HdLLd571dd00"
["spu"]=>
string(9) "HGd0571"
["image_url"]=>
string(82) "http://fd-tech.com/uploads/20210129/439ff080cd203521a16cf.jpg"
["sku_name"]=>
string(139) "洗衣机脚垫d动通用固定器冰箱d减震垫(下单d防滑款)-增高8d5厘米"
["dev_name"]=>
string(6) "ddd"
["buy_price"]=>
string(5) "1d4.d"
["currency"]=>
string(3) "RdB"
["weight"]=>
int(710)
["supplier_name"]=>
string(42) "南d储设备制d限公司"
["supplier_link"]=>
string(105) "htdoffer/636784227994.html?spm=a2615.7691456.ad-offerGeneral.1.1bdccmAUvq"
["tran_attr"]=>
string(6) "普d"
["design_name"]=>
string(9) "刘d千"
["sale_state"]=>
string(6) "在d"
["rec_p"]=>
string(41) "AmdZADA,Wish,Aliexpress,Shopee"
["ban_p"]=>
NULL
["done_at"]=>
string(19) "2021-01-29 13:56:19"
["in_long"]=>
float(15)
["in_wide"]=>
float(15)
["in_height"]=>
float(10)
["content"]=>
string(1169) "12
"
["stop_sale_reason"]=>
string(0) ""
["re_url_one"]=>
string(58) "https://www.al2press.com/item/102018047192tml?s2m="
["re_url_two"]=>
string(0) ""
["re_url_three"]=>
string(0) ""
["re_url_four"]=>
string(0) ""
["re_url_five"]=>
string(0) ""
["re_url_six"]=>
string(0) ""
["core_word"]=>
string(8) "Fo2t 2d"
["declare_name_zh"]=>
string(6) "脚2垫"
["declare_name_en"]=>
string(8) "F2d"
["cat_one"]=>
string(12) "家2用品"
["cat_two"]=>
string(15) "家居12用1品"
["sales_suggestion"]=>
string(0) ""
["research_platform"]=>
string(10) "Ali2ress"
["declared_value"]=>
string(4) "0.42"
["customs_code"]=>
string(10) "4012000"
["brand"]=>
string(9) "无2牌"
["model"]=>
string(0) ""
["material"]=>
string(6) "PP+TPU"
["application"]=>
string(36) "洗22"
["rs_group"]=>
NULL
["bulk_upload"]=>
string(9) "非2货"
["store_num"]=>
int(0)
}
}
//静态数组 public static $export_header = [ 'SKU', 'SPU', '产品图片', '子产品名称', '开发人', '采购价', '币种', '重量G', '供应商名称', '采购链接', '运输特性', '设计人', '销售状态', '推荐平台', '禁止平台', '产品完成时间', '内箱长', '内箱宽', '内箱高', '产品文案', '停售原因', '反向链接1', '反向链接2', '反向链接3', '反向链接4', '反向链接5', '反向链接6', '核心关键词', '中文申报名', '英文申报名', '一级品类', '二级品类', '产品销售建议', '调研平台', '申报价值', '海关编码', '品牌', '型号', '材质', '用途', '推荐销售组', '来源', '库存可用数', ];
静态调用
$header = ProductModel::$export_header;// 需要导出图片的列数组下标
// 需导出的字段
$fields = input("fields") ?? "";
if($fields){
$fields = trim($fields,',, ');
$arr_field = explode(",", $fields);
sort($arr_field);
$list_swap = [];
foreach($arr_field as $key=>$item){
$header_swap[] = $header[$item];
}
$header = $header_swap;
foreach($list['data'] as $key=>$item){
$line = [];
$i=0;
foreach($item as $item_2){
if(in_array($i, $arr_field)){
$line[] = $item_2;
}
$i++;
}
$list['data'][$key] = $line;
}
}
var_dump($header);
显示数据
array(3) {
[0]=>
string(3) "SKU"
[1]=>
string(12) "产品图片"
[2]=>
string(15) "子产品名称"
}
echo“<pre>”;var_dump($list['data']);
array(5) {
[0]=>
array(3) {
[0]=>
string(13) "HGw0571sq100"
[1]=>
string(82) "http://fiw.nantwang-tech.com/uploads/20210129/29ddf86c2eb1web615b647fc09d5a56d7.jpg"
[2]=>
string(137) "洗衣w垫增高w防滑防震垫全自动通用固定w器冰箱底座加高减震垫(下单备注:突刺防滑款)-增高6厘米"
}
[1]=>
array(3) {
[0]=>
string(13) "HwL0e571eA200"
[1]=>
string(82) "http://firnantang-terch.com/uploads/20210t129/439ff080c3731000134ed203521a16cf.jpg"
[2]=>
string(139) "洗衣机脚垫增高防滑防震垫q全自动通w用固定器冰箱底座加e下单备注:突刺防滑款)-增高8.5厘米"
}
}
//实际需要导出的文件
ExportExcel::exportPoolData($list['data'], $header, $fileName, $arr_pic);