本帖最后由 Richard.Huang 于 2024-1-31 11:23 编辑
产品:SpreadJS
版本:V16.2.6
接口返回的数据格式如下json:
将返回的数据从第六行开始铺, 根据接口返回的数据量, 在第7行动态插入行,每行复制第六行的样式计算公式。
目前设置数据的操作是,先更具数据量增加行, 然后copy模板行上的公式 数据 等, 然后 在设置数据:, 但是 目前根据行号列号设置数据,这样每次模板表更新都会出现数据设置错位置的问题。 所以我在第3行新加了 一行 作为唯一的列号标识, 如何快速的将数据对应的绑定上?并且从指定的行开始铺数?
- // steps1: 新增行
- sheet.addRows(6, datas.length - 1);
- // steps2: copy
- datas.forEach((item, index) => {
- if (index != 0) {
- // 剩下的数据就直接 搞到 新增的行上
- sheet.copyTo(
- 5,
- 0,
- 5 + index,
- 0,
- 1,
- sheet.getColumnCount(),
- GC.Spread.Sheets.CopyToOptions.all
- );
- // step3: 目前设置值的方式
- sheet.setValue(5 + index, 0, item.id);
- sheet.setValue(5 + index, 1, index + 1);
- sheet.setValue(5 + index, 2, item.col1);
- } else {
- // 将第一条数据设置到模板行对应的格子上
- sheet.setValue(5, 0, item.id);
- sheet.setValue(5, 1, index + 1);
- sheet.setValue(5, 2, item.col2);
- }
- });
复制代码- [
- {
- id: 1,
- col1: "",
- col2: "",
- col3: "",
- col4: "",
- col5: "",
- col6: "",
- },
- {
- id: 1,
- col1: "",
- col2: "",
- col3: "",
- col4: "",
- col5: "",
- col6: "",
- },
- ];
复制代码
|
|