1

I want to export xlsx files using js-xlsx on my Node.JS server. 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!

4

1 回答 1

0

我今天自己偶然发现了这一点,并花了一些时间找到原因。解决方案是在工作表中设置“!ref”值:

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

“!ref”用于定义工作表中包含数据的区域。这是来自官方文档:

sheet['!ref']:表示工作表范围的基于 A-1 的范围。使用工作表的函数应使用此参数来确定范围。分配在范围之外的单元格不会被处理。特别是在手写工作表时,不包括范围之外的单元格

于 2017-08-25T12:58:00.237 回答