如何使用Angular或Node JS在现有的Excel文件中编写 [英] How to write in existing excel file using angular or node js

查看:73
本文介绍了如何使用Angular或Node JS在现有的Excel文件中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我被困在平均堆栈中,并且我的项目中要求将数据写入现有的micros中,以启用经过验证的excel工作表.我做了很多谷歌,但我没有找到满足我要求的任何节点或角度模块.每个人都给我选项来创建新文件,没有人给我选项来更新现有的excel.真的很奇怪

I am stuck actually i am working in a mean stack and i have a requirement in my project to write data in existing micros enable validated excel sheet. I do a lot of google but i did't find any node or angular module those are fulfill my requirement. Everyone given me option to create new file no one give me option update existing excel. Its really strange

以下是我的逐步要求

  1. 我有一个微型启用excel(.xlsm)
  2. 现在我必须打开它并用angular或node js写入一些数据.
  3. 之后,将其扔给用户进行下载.

请帮助我任何人

推荐答案

SheetJS API允许您将Microsoft Excel(.xls/.xlsx)和OpenDocument(.ods)格式转换为JSON流或文件以及从MongoDB或MongooseJS导入/导出.只需学习简单的API.

The SheetJS API allow you convert Microsoft Excel (.xls / .xlsx) and OpenDocument (.ods) formats to JSON stream or files and import/export from/to MongoDB or MongooseJS. Just study the simple and easy API.

在Github中,您可以找到文档,教程和代码示例.

In Github you can find the documentation, tutorials and code examples.

站点: http://sheetjs.com/

项目:: https://github.com/SheetJS/js-xlsx

交互式演示: http://oss.sheetjs.com/js -xlsx/

使用下面的代码示例,但要在运行npm install xlsx之前,然后将代码块打开以打开.xlsm文件:var workbook = XLSX.readFile('test.xlsx');.

Use the code example below, but just before run npm install xlsx and put the chunk of code to open the .xlsm file: var workbook = XLSX.readFile('test.xlsx');.

/* require XLSX */
var XLSX = require('xlsx')

function datenum(v, date1904) {
    if(date1904) v+=1462;
    var epoch = Date.parse(v);
    return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
}

function sheet_from_array_of_arrays(data, opts) {
    var ws = {};
    var range = {s: {c:10000000, r:10000000}, e: {c:0, r:0 }};
    for(var R = 0; R != data.length; ++R) {
        for(var C = 0; C != data[R].length; ++C) {
            if(range.s.r > R) range.s.r = R;
            if(range.s.c > C) range.s.c = C;
            if(range.e.r < R) range.e.r = R;
            if(range.e.c < C) range.e.c = C;
            var cell = {v: data[R][C] };
            if(cell.v == null) continue;
            var cell_ref = XLSX.utils.encode_cell({c:C,r:R});

            if(typeof cell.v === 'number') cell.t = 'n';
            else if(typeof cell.v === 'boolean') cell.t = 'b';
            else if(cell.v instanceof Date) {
                cell.t = 'n'; cell.z = XLSX.SSF._table[14];
                cell.v = datenum(cell.v);
            }
            else cell.t = 's';

            ws[cell_ref] = cell;
        }
    }
    if(range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
    return ws;
}

/* original data */
var data = [[1,2,3],[true, false, null, "sheetjs"],["foo","bar",new Date("2014-02-19T14:30Z"), "0.3"], ["baz", null, "qux"]]
var ws_name = "SheetJS";

function Workbook() {
    if(!(this instanceof Workbook)) return new Workbook();
    this.SheetNames = [];
    this.Sheets = {};
}

var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);

/* add worksheet to workbook */
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;

/* write file */
XLSX.writeFile(wb, 'test.xlsx');

这篇关于如何使用Angular或Node JS在现有的Excel文件中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆