spread17.0.0 反序列化json问题请教
本帖最后由 Wilson.Zhang 于 2025-1-6 10:14 编辑<div class="blockcode"><blockquote>var soucre= {
"style": "{\"version\":\"17.1.7\",\"name\":\"\",\"docProps\":{\"docPropsCore\":{\"created\":\"2025-01-04T00:23:17Z\"}},\"sheetCount\":1,\"customList\":[],\"defaultSheetTabStyles\":{},\"builtInFileIcons\":{},\"sheets\":{\"Sheet1\":{\"name\":\"Sheet1\",\"isSelected\":true,\"rowCount\":1,\"columnCount\":90,\"visible\":1,\"theme\":\"Office\",\"data\":{\"defaultDataNode\":{\"style\":{\"themeFont\":\"Body\"}}},\"rowHeaderData\":{\"defaultDataNode\":{\"style\":{\"themeFont\":\"Body\"}}},\"colHeaderData\":{\"defaultDataNode\":{\"style\":{\"themeFont\":\"Body\"}}},\"columns\":[{\"name\":\"_a\",\"displayName\":\"月份\",\"format\":\"string\"},{\"name\":\"_b\",\"displayName\":\"装炉日期\",\"size\":125},{\"name\":\"_c\",\"displayName\":\"出炉日期\"},{\"name\":\"_d\",\"displayName\":\"喷砂日期\",\"width\":200,\"size\":200},{\"name\":\"_e\",\"displayName\":\"报检日期\",\"width\":200,\"size\":200},{\"name\":\"_f\",\"displayName\":\"全部出完日期\",\"width\":250,\"size\":250},{\"name\":\"_g\",\"displayName\":\"炉号1\",\"width\":150,\"size\":150},{\"name\":\"_h\",\"displayName\":\"炉号\",\"width\":150,\"size\":150},{\"name\":\"_i\",\"displayName\":\"炉次\",\"width\":150,\"size\":150},{\"name\":\"_j\",\"displayName\":\"行业\",\"width\":150,\"size\":150},{\"name\":\"_k\",\"displayName\":\"名称类\",\"width\":150,\"size\":150},{\"name\":\"_l\",\"displayName\":\"名称\",\"width\":150,\"size\":150},{\"name\":\"_m\",\"displayName\":\"规格型号\",\"width\":250,\"size\":250},{\"name\":\"_n\",\"displayName\":\"型号\",\"width\":150,\"size\":150},{\"name\":\"_o\",\"displayName\":\"厂家\",\"width\":150,\"size\":150},{\"name\":\"_p\",\"displayName\":\"泥料编号\",\"width\":250,\"size\":250},{\"name\":\"_q\",\"displayName\":\"泥料编号1\",\"width\":250,\"size\":250},{\"name\":\"_r\",\"displayName\":\"类型\",\"width\":150,\"size\":150},{\"name\":\"_s\",\"displayName\":\"类型1\",\"width\":150,\"size\":150},{\"name\":\"_t\",\"displayName\":\"金属硅比例\",\"width\":200,\"size\":200},{\"name\":\"_u\",\"displayName\":\"层次\",\"width\":150,\"size\":150},{\"name\":\"_v\",\"displayName\":\"位置\",\"width\":150,\"size\":150},{\"name\":\"_w\",\"displayName\":\"毛坯1\",\"width\":150,\"size\":150},{\"name\":\"_x\",\"displayName\":\"毛坯2\",\"width\":150,\"size\":150},{\"name\":\"_y\",\"displayName\":\"复烧次数\",\"width\":150,\"size\":150},{\"name\":\"_z\",\"displayName\":\"直线度范围\",\"width\":200,\"size\":200},{\"name\":\"_aa\",\"displayName\":\"工艺\",\"width\":150,\"size\":150},{\"name\":\"_ab\",\"displayName\":\"装炉数量\",\"width\":150,\"size\":150},{\"name\":\"_ac\",\"displayName\":\"核算1\",\"width\":150,\"size\":150},{\"name\":\"_ad\",\"displayName\":\"A类\",\"width\":150,\"size\":150},{\"name\":\"_ae\",\"displayName\":\"B类\",\"width\":150,\"size\":150},{\"name\":\"_af\",\"displayName\":\"C类\",\"width\":150,\"size\":150},{\"name\":\"_ag\",\"displayName\":\"D类\",\"width\":150,\"size\":150},{\"name\":\"_a\",\"displayName\":\"核算3\",\"width\":150,\"size\":150},{\"name\":\"_du\",\"displayName\":\"A级\",\"width\":150,\"size\":150},{\"name\":\"_dv\",\"displayName\":\"B级\",\"width\":150,\"size\":150},{\"name\":\"_dw\",\"displayName\":\"C级\",\"width\":150,\"size\":150},{\"name\":\"_dx\",\"displayName\":\"D级\",\"width\":150,\"size\":150},{\"name\":\"_dy\",\"displayName\":\"E级\",\"width\":150,\"size\":150},{\"name\":\"_dz\",\"displayName\":\"核算2\",\"width\":150,\"size\":150},{\"name\":\"_ai\",\"displayName\":\"研磨断\",\"width\":150,\"size\":150},{\"name\":\"_aj\",\"displayName\":\"喷砂断\",\"width\":150,\"size\":150},{\"name\":\"_ak\",\"displayName\":\"出炉断\",\"width\":150,\"size\":150},{\"name\":\"_al\",\"displayName\":\"承受力断裂\",\"width\":150,\"size\":150},{\"name\":\"_am\",\"displayName\":\"暗裂纹\",\"width\":150,\"size\":150},{\"name\":\"_an\",\"displayName\":\"尺寸\",\"width\":150,\"size\":150},{\"name\":\"_ao\",\"displayName\":\"凹坑\",\"width\":150,\"size\":150},{\"name\":\"_ap\",\"displayName\":\"直线度\",\"width\":150,\"size\":150},{\"name\":\"_aq\",\"displayName\":\"发绿\",\"width\":150,\"size\":150},{\"name\":\"_ar\",\"displayName\":\"不熟\",\"width\":150,\"size\":150},{\"name\":\"_as\",\"displayName\":\"磕碰\",\"width\":150,\"size\":150},{\"name\":\"_at\",\"displayName\":\"出炉掉块\",\"width\":150,\"size\":150},{\"name\":\"_au\",\"displayName\":\"变形\",\"width\":150,\"size\":150},{\"name\":\"_av\",\"displayName\":\"内硅\",\"width\":150,\"size\":150},{\"name\":\"_aw\",\"displayName\":\"凹陷\",\"width\":150,\"size\":150},{\"name\":\"_ax\",\"displayName\":\"分层\",\"width\":150,\"size\":150},{\"name\":\"_ay\",\"displayName\":\"表面烧糠\",\"width\":150,\"size\":150},{\"name\":\"_az\",\"displayName\":\"表面不平\",\"width\":150,\"size\":150},{\"name\":\"_ba\",\"displayName\":\"让发绿\",\"width\":150,\"size\":150},{\"name\":\"_bb\",\"displayName\":\"让尺寸\",\"width\":150,\"size\":150},{\"name\":\"_bc\",\"displayName\":\"让表面\",\"width\":150,\"size\":150},{\"name\":\"_bd\",\"displayName\":\"让掉块\",\"width\":150,\"size\":150},{\"name\":\"_be\",\"displayName\":\"让内硅\",\"width\":150,\"size\":150},{\"name\":\"_bf\",\"displayName\":\"让裂纹\",\"width\":150,\"size\":150},{\"name\":\"_bg\",\"displayName\":\"让直线度\",\"width\":150,\"size\":150},{\"name\":\"_bh\",\"displayName\":\"实验1\",\"width\":150,\"size\":150},{\"name\":\"_db\",\"displayName\":\"研磨质量\",\"width\":200,\"size\":200},{\"name\":\"_dc\",\"displayName\":\"备注1\",\"width\":200,\"size\":200},{\"name\":\"_dd\",\"displayName\":\"备注2\",\"width\":200,\"size\":200},{\"name\":\"_de\",\"displayName\":\"挤出人员\",\"width\":200,\"size\":200},{\"name\":\"_df\",\"displayName\":\"石墨实验\",\"width\":200,\"size\":200},{\"name\":\"_dg\",\"displayName\":\"综合实验\",\"width\":200,\"size\":200},{\"name\":\"_eg\",\"displayName\":\"产品分类\",\"width\":150,\"size\":150},{\"name\":\"_di\",\"displayName\":\"板材分类\",\"width\":200,\"size\":200},{\"name\":\"_dj\",\"displayName\":\"是否打表\",\"width\":200,\"size\":200},{\"name\":\"_dk\",\"displayName\":\"标识/金属硅\",\"width\":200,\"size\":200},{\"name\":\"_dl\",\"displayName\":\"金属硅批号\",\"width\":200,\"size\":200},{\"name\":\"_dm\",\"displayName\":\"直线度要求\",\"width\":200,\"size\":200},{\"name\":\"_dn\",\"displayName\":\"炭黑\",\"width\":200,\"size\":200},{\"name\":\"_en\",\"displayName\":\"烧结曲线\",\"width\":150,\"size\":150},{\"name\":\"_do\",\"displayName\":\"自定义1\",\"width\":200,\"size\":200},{\"name\":\"_dp\",\"displayName\":\"自定义2\",\"width\":200,\"size\":200},{\"name\":\"_dq\",\"displayName\":\"自定义3\",\"width\":200,\"size\":200},{\"name\":\"_dr\",\"displayName\":\"自定义4\",\"width\":200,\"size\":200},{\"name\":\"_ds\",\"displayName\":\"自定义4\",\"width\":200,\"size\":200},{\"name\":\"_dt\",\"displayName\":\"自定义4\",\"width\":200,\"size\":200},{\"name\":\"bill_code\",\"displayName\":\"报工单号\",\"width\":200,\"size\":200},{\"name\":\"work_ordert\",\"displayName\":\"派工单号\",\"width\":200,\"size\":200},{\"name\":\"production_code\",\"displayName\":\"派工单号\",\"width\":200,\"size\":200},{\"name\":\"sale_order_code\",\"displayName\":\"销售单号\",\"width\":200,\"size\":200}],\"defaultData\":{},\"leftCellIndex\":0,\"topCellIndex\":0,\"selections\":{\"0\":{\"row\":0,\"col\":0,\"rowCount\":1,\"colCount\":1},\"length\":1},\"rowOutlines\":{\"items\":[]},\"columnOutlines\":{\"items\":[]},\"cellStates\":{},\"states\":{},\"outlineColumnOptions\":{},\"autoMergeRangeInfos\":[],\"shapeCollectionOption\":{\"snapMode\":0},\"printInfo\":{\"paperSize\":{\"width\":850,\"height\":1100,\"kind\":1}},\"index\":0,\"order\":0}},\"sheetTabCount\":0,\"namedPatterns\":{}}",
"data": [
{
"banchengpin_status": "0",
"erjipin_status": "1",
"notice_sub_id": "7917424141119933372",
"dispatch_sub_id": "0194107ab8907320ad3445d12eaa0bbe",
"sale_son_id": "",
"bill_code": "W202412310061",
"work_ordert": "D202412290005",
"production_code": "MO_ST2024121809",
"sale_order_code": null,
"rowNo": null,
"_a": "",
"_b": "2024-12-31",
"_c": "",
"_d": "",
"_e": "",
"_f": "",
"_g": "0",
"_h": null,
"_i": "0",
"_j": "",
"_k": "辊棒",
"_l": "辊棒",
"_m": "φ46*φ34*6*3120",
"_n": "",
"_o": null,
"_p": "D20241231-09",
"_q": "",
"_r": null,
"_s": "",
"_t": "",
"_u": "2",
"_v": "南中",
"_w": "",
"_x": "",
"_y": "",
"_z": "",
"_aa": "",
"_ab": "20",
"_ac": "",
"_ad": "",
"_ae": "",
"_af": "",
"_ag": "",
"_ah": "",
"_ai": "",
"_aj": "",
"_ak": "",
"_al": "",
"_am": "",
"_an": "",
"_ao": "1",
"_ap": "2",
"_aq": "",
"_ar": "",
"_as": "",
"_at": "",
"_au": "",
"_av": "",
"_aw": "",
"_ax": "",
"_ay": "",
"_az": "",
"_ba": "",
"_bb": "",
"_bc": "",
"_bd": "",
"_be": "",
"_bf": "",
"_bg": "",
"_bh": "",
"_bi": "",
"_bj": "",
"_bk": "",
"_bl": "",
"_bm": "",
"_bn": "",
"_bo": "",
"_bp": "",
"_bq": "",
"_br": "",
"_bs": "",
"_bt": "",
"_bu": "",
"_bv": "",
"_bw": "",
"_bx": "",
"_by": "",
"_bz": "",
"_ca": "",
"_cb": "",
"_cc": "",
"_cd": "",
"_ce": "",
"_cf": "",
"_cg": "",
"_ch": "",
"_ci": "",
"_cj": "",
"_ck": "",
"_cl": "",
"_cm": "",
"_cn": "",
"_co": "",
"_cp": "",
"_cq": "",
"_cr": "",
"_cs": "",
"_ct": "",
"_cu": "",
"_cv": "",
"_cw": "",
"_cx": "",
"_cy": "",
"_cz": "",
"_da": "",
"_db": "",
"_dc": "",
"_dd": "",
"_de": "",
"_df": "",
"_dg": "",
"_dh": "",
"_di": "",
"_dj": "",
"_dk": "",
"_dl": "",
"_dm": "",
"_dn": "",
"_do": "",
"_dp": "",
"_dq": "",
"_dr": "",
"_ds": "",
"_dt": "",
"_du": "1",
"_dv": "2",
"_dw": "3",
"_dx": "4",
"_dy": "",
"_dz": "",
"id": "01941b59890f72889ad38c4340a2db57",
"createTime": "2024-12-31 02:30:54",
"createId": "",
"modifyTime": "2024-12-31 02:30:54",
"modifyId": ""
}
]
}
var sheet = spread.getActiveSheet();
spread.fromJSON(JSON.parse(soucre.style))
sheet.setDataSource(soucre.data);
数据不显示,标题也不显示
您好!您提供的json数据格式不太正确,请教下您的json数据来源。
我分析过您提供的json数据,理解您需要反序列化的是source.style,之后再对Worksheet设置数据源source.data。我将您的json数据拆解后可以正常设置,在此不讨论您数据中的属性列名称,如下图所示:
将拆解后的json数据同步给您测试,分别为style.json和data.json:
Wilson.Zhang 发表于 2025-1-6 10:20
您好!您提供的json数据格式不太正确,请教下您的json数据来源。
我分析过您提供的json数据,理解您需要 ...
表头需要显示名称,需要使用缓存数据
Typing. 发表于 2025-1-6 10:53
表头需要显示名称,需要使用缓存数据
您的source.style中没有列头数据的定义,如下图左侧为您提供的json,右侧为正常包含列头数据的json。
这才导致绑定数据后没有对应的表头数据,建议您在SpreadJS中重新制作设置表头后导出为json数据使用。
Wilson.Zhang 发表于 2025-1-6 16:48
您的source.style中没有列头数据的定义,如下图左侧为您提供的json,右侧为正常包含列头数据的json。
...
我用了spread.toJSON({ includeBindingSource: false });保存样式,保存的样式不显示表头 您参考下附件demo代码,经测试是可以正常显示列头和相关数据的,如下所示:
spread.fromJSON(styleJson);
let sheet = spread.getActiveSheet();
sheet.autoGenerateColumns = false;
sheet.setDataSource(data);
页:
[1]