angularJS:导出的文件具有二进制数据

时间:2018-08-02 05:20:44

标签: angularjs

   if (!!docs.length) {
                    var workbook = { SheetNames: [], Sheets: {} };

                    var ws = buildbilldetailsarray(docs);
                    workbook.SheetNames.push('BillDetails');
                    workbook.Sheets['BillDetails'] = ws;
                    var wopts = { bookType: 'xlsx', bookSST: false, type: 'binary' };
                    var wbout = XLSX.write(workbook, wopts);

                    var temp = {};
                    temp.filename = moment(appUtils.getNewDate()).local().format('YYYY-MM-DD HH:mm:ss') + "_billdetails.xlsx";
                    temp.filedata = wbout;
                    var filePath = './app/thirdparty/sapreports/';
                    fs.exists(filePath, function (exists) {
                        if (exists) {
                            fs.writeFile(filePath + "/" + temp.filename, temp, function (err) {
                                if (err) {
                                    res.status(500).json({ err: err });
                                    return;
                                } else {
                                    // res.setHeader('Content-disposition', 'attachment; filename=' + temp.filename);
                                    // res.setHeader('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                                    res.status(200).json({ exportdata: temp });
                                }
                            });
                        }
                        else {
                            fs.mkdir(filePath, function (err) {
                                if (err) {
                                    res.status(500).json({ err: err });
                                    return;
                                } else {
                                    fs.writeFile(filePath + "/" + temp.filename, temp, function (err, res) {
                                        if (err) {
                                            res.status(500).json({ err: err });
                                            return;
                                        } else {
                                            // res.setHeader('Content-disposition', 'attachment; filename=' + temp.filename);
                                            // res.setHeader('Content-type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                                            res.status(200).json({ exportdata: temp });
                                        }
                                    });
                                }
                            });
                        }
                    });
                } else {
                    res.status(500).json({ error: 'No Data' });
                }

在上面的代码中,我将excel文件导出到服务器。但是文件包含这样的数据。![If i stringify [object][object], it is in binary format. What should I do to display the data in string format in excel file.] 1

0 个答案:

没有答案