如何在js

时间:2017-02-08 12:40:56

标签: javascript angularjs node.js xls fs

我可以将数据写入xls表格,但不能以合适的方式写入,请参阅下面的图片

My xls sheet

我的代码,

var readString = '';
      readString = "Name"+"\t"+" From"+"\t"+" Created By"+"\t"+" Reminder Date"+"\t"+" Reminder Time"+"\n";
      event.forEach(function (v, i) {
        readString += v.attributes.task_name+"\t";
        readString += v.attributes.context_type+"\t";
        readString += v.created_by.employee.name+"\t";
        readString += v.attributes.reminder_date+"\t";
        readString += v.attributes.reminder_time+"\t";
        readString += "\n";
      });
      var currTime = new Date().getTime();
      var filePath = "./modules/upload/excel/task_" + currTime + ".xls";
      //studentInfo.filePath = "task_" + currTime + ".xls";
      var writeStream = fs.createWriteStream(filePath);
      writeStream.write(readString);
      writeStream.close();

任何人都可以帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

要使用XLS文件,请参阅:

但是看看你的代码,你似乎在使用TSV数据,而不是XLS。参见:

请注意,TSV与CSV相同,唯一的区别是分隔符。