Quick Start

Overview

Tablebundle provides a set of open sdk, which can realize the realization from .tablebundle file to snapshot. APITable can render interface based on snapshot.



Read Snapshot From File


import TableBundle from 'tablebundle';

try{
  const tableBundle = TableBundle.loadFile('path/xxxx/file.tablebundle');
  
  
  // get all node(datasheet folder) map
  //const nodeMap: TableBundle.DatasheetMap = tablebundle.getMap();
  
  // get a TableBundleDatasheet
  const datasheet: DatasheetSnptshot = tablebundle.getDatasheet('dstxxxx');
  
  // get TableBundle Snapshot
  const snapshot = datasheet.getSnapshot();
  
  // attachments
  const assets = datasheet.getAssets(); 

  console.log(snapshot);
}catch(e){
  console.log('error happens while read table data', e)
}


Write Snapshot To File

import TableBundle from 'tablebundle';

// transform custom snapshot into TableBundle Snapshot
// The transform function needs to be implemented by oneself
const snapshot: TableBundle.Snapshot = { ... }; // 


const datasheet = new TableBundleDataSheet(snapshot);
const datasheetMap: TableBundleDatasheetMap = {
   "xxx": datasheet
}

const tableBundle = TableBundle.new()
tableBundle.apply(datasheetMap);

try{
  tableBundle.save('path/xxxx/file.tablebundle');
}catch(e){
  console.log('error happens while write table bundle to file', e)
}


How to customize your own TableBundle

You can use the TableBundle SDK to export the .tableBundle file in the browser extension or in your own program.

Assuming you are developing a program that converts files of type xlsx to .tablebundle, you can follow the example code below.

import TableBundle from 'tablebundle';
import XLSX from 'xlsx';

// load xlsx file
const workbook = XLSX.readFile('path/to/your/file.xlsx');

// get the fiest worksheer
const worksheet = workbook.Sheets[workbook.SheetNames[0]];

// convert worksheet to json
const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });

const tableBundle = TableBundle.new()

// transform work sheet jsonData into TableBundle Snapshot
// The transform function needs to be implemented by oneself
const snapshot = transform(jsonData);

const datasheet = new TableBundleDataSheet(snapshot);

tableBundle.apply(datasheet);

try{
  tableBundle.save('path/xxxx/file.tablebundle');
}catch(e){
  console.log('error happens while write table bundle to file', e)
}