SuperAPI AI Directory

wecom-smartsheet

Office & productivity

View repository

Updated 10-15 17:29

About this skill

WeCom smart sheet reading

WeCom smart sheets are rendered with Canvas, and the DOM has no cell data, but the complete data model is stored in JS memory.

Entry

window.getPreloadedTablesManager()
  → mgr.getCompleteTableByTableId(tableId)   // 异步,必须 await

Extract parameters from the URL:tab= → tableId,viewId= → viewId。

Read

async () => {
  const mgr = window.getPreloadedTablesManager();
  const table = await mgr.getCompleteTableByTableId(TABLE_ID);
  const v = table.views.find(v => v.id === VIEW_ID);
  const rids = v.properties.recordIds.slice(0, N);
  const fids = v.properties.fieldIds;
  const fieldMap = {};
  for (const fid of fids) {
    const f = table.getFieldByFieldId(fid);
    fieldMap[fid] = f ? f.title : fid;
  }
  const rows = [];
  for (const rid of rids) {
    const row = { _id: rid };
    for (const fid of fids) {
      const cell = table.getCell(rid, fid);
      if (!cell || !cell.value) { row[fieldMap[fid]] = null; continue; }
      const val = cell.value;
      const f = table.getFieldByFieldId(fid);
      if (Array.isArray(val) && (f.type === 9 || f.type === 17)) {
        const opts = (f.property && f.property.options) || [];
        row[fieldMap[fid]] = val.map(v => { const o = opts.find(o => o.id === v); return o ? o.text : v; });
      } else if (Array.isArray(val)) {
        row[fieldMap[fid]] = val.map(v => v.text || v.title || v.id || v).join('');
      } else if (typeof val === 'object') {
        row[fieldMap[fid]] = val.text || val.seq || JSON.stringify(val);
      } else { row[fieldMap[fid]] = val; }
    }
    rows.push(row);
  }
  return JSON.stringify(rows).substring(0, 4000);
}

Field type quick reference

type Meaning value format
1 Text [{type:'text', text:'...'}]
2 Number Numeric value
4 Date Millisecond timestamp
5 Attachment [{title, imageUrl}]
7 Member [{id:'userId'}]
9 Multiple choice ['optionId'], needs to be translated from field.property.options ['optionId'] , needs to be translated from field.property.options
17 Single choice Same as above
25 Auto number {seq, text}

For more field types, see references/field-types.md. For the complete API method list, see references/api-methods.md。

Notes

  • getCompleteTableByTableId returns a Promise, must await
  • Read large tables in batches (50-100 rows each time) to avoid evaluate timeouts
  • Truncate the evaluate return value with JSON.stringify().substring(0, N) JSON.stringify().substring(0, N)
  • The view's recordIds has already been filtered and sorted, reflecting the order the user sees
  • open/navigate may report a timeout but the page has actually loaded; just confirm with tabs