简体   繁体   English

正确处理js-xlsx中xlsx的内容并对其进行操作

[英]Correctly address content of xlsx in js-xlsx and manipulate it

I want to export xlsx files using js-xlsx on my Node.JS server. 我想在我的Node.JS服务器上使用js-xlsx导出xlsx文件。 I can read files and save them. 我可以读取文件并保存。 But as i try to fill the Table with content it does not work. 但是当我尝试用内容填充表格时它不起作用。

I fill it using lines like these: 我用这样的行填充它:

for (var i = 0; i < workbook.SheetNames.length; i++) {
    var sheet = workbook.Sheets[workbook.SheetNames[i]];
    var studenten = stapel[workbook.SheetNames[i]];

    sheet["A1"] = {v: "This is a test!",t:"s"};

    workbook.Sheets[workbook.SheetNames[i]] = sheet;
}

, I tried using this notation for the cell address too ,我也尝试将这种表示法用于单元格地址

{c:0,r:0}

but as i export my file the tables are empty. 但是当我导出我的文件时,表格是空的。 Creating different worksheets works fine but i can't fill the tables with content. 创建不同的工作表工作正常,但我不能用内容填充表格。 Could someone here enlighten me on how to correctly address the tables and manipulate their content? 有人可以告诉我如何正确地解决表格并操纵他们的内容吗?

Thanks in advance! 提前致谢!

update: even 更新:甚至

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

var workbook = new Workbook();
workbook.SheetNames.push("1");
workbook.Sheets[1] = {'A1': {v: "HI",t:"s"}};

doesn't work. 不起作用。 I think I don't understand the API! 我想我不懂API!

I stumbled upon this today myself and took some time to find the reason. 我今天偶然发现了这个,花了一些时间才找到原因。 The solution is to set the "!ref" Value in a worksheet: 解决方案是在工作表中设置“!ref”值:

workbook.Sheets[1] = {'!ref': "A1", 'A1': {v: "HI",t:"s"}};

The "!ref" is used to define the area that contains data within the sheet. “!ref”用于定义包含工作表内数据的区域。 This is from the official documentation: 这来自官方文件:

sheet['!ref'] : A-1 based range representing the sheet range. sheet ['!ref'] :基于A-1的范围,表示工作表范围。 Functions that work with sheets should use this parameter to determine the range. 使用工作表的函数应使用此参数来确定范围。 Cells that are assigned outside of the range are not processed . 不处理在范围之外分配的单元格 In particular, when writing a sheet by hand, cells outside of the range are not included 特别是,当用手书写纸张时,不包括该范围之外的单元格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM