xspreadsheet+xlsx实现可打开本地excel表格编辑并保存下载在线电子表格代码
代码语言:html
所属分类:表格
代码描述:xspreadsheet+xlsx实现可打开本地excel表格编辑并保存下载在线电子表格代码
代码标签: 打开 本地 excel 表格 编辑 并 保存 下载 在线 电子 表格
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>BFW NEW PAGE</title> <script id="bfwone" data="dep=jquery-3.2.1.min|xspreadsheet|xlsx.full.min&err=0" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script> <script type="text/javascript"> var fllename = "bfw.xls"; function stox(wb) { var out = []; wb.SheetNames.forEach(function(name) { var o = { name: name, rows: {}}; var ws = wb.Sheets[name]; var aoa = XLSX.utils.sheet_to_json(ws, { raw: false, header: 1 }); aoa.forEach(function(r, i) { var cells = {}; r.forEach(function(c, j) { cells[j] = ({ text: c }); }); o.rows[i] = { cells: cells }; }) out.push(o); }); return out; } function xtos(sdata) { var out = XLSX.utils.book_new(); sdata.forEach(function(xws) { var aoa = [[]]; var rowobj = xws.rows; for (var ri = 0; ri < rowobj.len; ++ri) { var row = rowobj[ri]; if (!row) continue; aoa[ri] = []; Object.keys(row.cells).forEach(function(k) { var idx = +k; if (isNaN(idx)) return; aoa[ri][idx] = row.cells[k].text; }); } var ws = XLSX.utils.aoa_to_sheet(aoa); XLSX.utils.book_append_sheet(out, ws, xws.name); }); return out; } bready(function() { use(["xspreadsheet-zh-cn", "xspreadsheet"], function() { x_spreadsheet.locale('zh-cn'); var grid = x_spreadsheet('#xspreadsheet'); $(".open").click(function() { $("#file").click(); }) $(".save").click(function() { /* build workbook from the grid d.........完整代码请登录后点击上方下载按钮下载查看
网友评论0