找回密码
 立即注册

QQ登录

只需一步,快速开始

FzcSuiY

最佳答案
最佳答案
Ellia.DuanSpreadJS 开发认证
超级版主   /  发表于:2023-10-17 11:26:25
来自 8#
FzcSuiY 发表于 2023-10-17 14:13
感谢回复! 但是你这只是改变了列头显示的文本吧,name和age字段也需要显示到第一行,不然不知道你下面的 ...

您好,可以在上述代码基础上,在第一行新增行,写入name,age等标识。
image.png713556213.png
结果如下
image.png796307983.png
相关代码如下:
  1.         let sheet = spread.getActiveSheet();

  2.         // 要绑定的数据
  3.         const persons = [
  4.             { name: 'Peter', age: 16 },
  5.             { name: 'Mark', age: 18 },
  6.             { name: 'John', age: 27 },
  7.             { name: 'Jane', age: 14 },
  8.         ]

  9.      // 列信息
  10.         const colInfos = [
  11.             { name: 'name', displayName: 'A' },
  12.             { name: 'age', displayName: 'B' },
  13.         ]
  14.         sheet.autoGenerateColumns = false
  15.         sheet.setDataSource(persons)
  16.         sheet.bindColumns(colInfos)
  17.         sheet.addRows(0,1)
  18.         sheet.setArray(0,0,[['name','age']])
复制代码



回复 使用道具 举报
12
您需要登录后才可以回帖 登录 | 立即注册
返回顶部