x-spreadsheet icon indicating copy to clipboard operation
x-spreadsheet copied to clipboard

Load Json Data Or Excel Data

Open Ponvijaykumar opened this issue 6 years ago • 8 comments

How to load existing excel date or json data

Ponvijaykumar avatar Feb 16 '19 10:02 Ponvijaykumar

new Spreadsheet("#x-spreadsheet-demo")
  .loadData({}) // load data (json data)
  .change(data => {
    // save data to db
  });

myliang avatar Feb 16 '19 11:02 myliang

Possible to load existing cvs or excel file.

Ponvijaykumar avatar Feb 18 '19 05:02 Ponvijaykumar

use a library to read in the CSV or Excel data. Some suggestions:

dodumosu avatar Feb 20 '19 08:02 dodumosu

加载存在数据库里的数据,你把数据转成demo中的数据格式不就可以了嘛

wangzhedong avatar Feb 20 '19 08:02 wangzhedong

加载存在数据库里的数据,你把数据转成demo中的数据格式不就可以了嘛

demo中的数据格式 中的 demo 在哪里

Leannechn avatar Mar 18 '20 10:03 Leannechn

https://docs.sheetjs.com/docs/demos/grid#x-spreadsheet discusses in more detail

Hosted script https://cdn.sheetjs.com/xspreadsheet/xlsxspread.min.js

Script exposes a function stox. Usage:

// var grid = x_spreadsheet(...);
var wb = XLSX.read(ab);
var new_data = stox(wb); // generate x-spreadsheet data
grid.loadData(new_data); // load data into x-spreadsheet

The SheetJS documentation includes examples for how to get the ab data. For example, data can be downloaded using fetch:

// const grid = x_spreadsheet(...);
(async() => {
  const url = "https://sheetjs.com/pres.numbers";
  const ab = await (await fetch(url)).arrayBuffer();
  grid.loadData(stox(XLSX.read(ab)));
})();

SheetJSDev avatar Mar 18 '20 16:03 SheetJSDev

Hello how can I add a custom button to the toolbar to import/export an excel file with https://github.com/SheetJS/sheetjs

nbao avatar Nov 26 '22 02:11 nbao

@SheetJSDev thank you for providing instructions, i'm facing a problem. after using xtos, i using sheet_to_html and would like it to display exact value of the column and not the formula, how to achieve this ?

here is my code :

const { xtos, stox } = require('./xs');
const XLSX = require('xlsx');
const { HyperFormula } = require('hyperformula');

var data = [
    { "name": "sheet2", "freeze": "A1", "styles": [], "merges": [], "rows": { "0": { "cells": { "0": { "text": "noms" }, "1": { "text": "value" } } }, "1": { "cells": { "0": { "text": "titre a" }, "1": { "text": "10000" } } }, "2": { "cells": { "0": { "text": "titre b" }, "1": { "text": "5000" } } }, "3": { "cells": { "0": { "text": "titre c" }, "1": { "text": "45495" } } }, "4": { "cells": { "0": { "text": "total" }, "1": { "text": "=sum(b2,b4)*0" } } }, "len": 100 }, "cols": { "len": 26 }, "validations": [], "autofilter": {} }
]

let workbook = xtos(data);

let elements = []
let output = [];
/* loop through the worksheet names in order */
for (var er in workbook.SheetNames) {
    //workbook.SheetNames.forEach(name => {
    var name = workbook.SheetNames[er];
    const worksheet = workbook.Sheets[name];
  
    const html = XLSX.utils.sheet_to_html(worksheet);
 
    /* add a header with the title name followed by the table */
    output.push(`<H3>${name}</H3>${html}`);

    console.log(html)
};```

emmanueladk avatar Jun 09 '24 23:06 emmanueladk