Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法正常返回数据,请帮忙看一下!谢谢 #3462

Closed
xinnian1992 opened this issue Feb 15, 2019 · 6 comments
Closed

无法正常返回数据,请帮忙看一下!谢谢 #3462

xinnian1992 opened this issue Feb 15, 2019 · 6 comments

Comments

@xinnian1992
Copy link

// save workbook to disk
const ctx=this.ctx;
workbook.xlsx.writeFile("./app/public/excel/first.xlsx").then(function () {
console.log("saved");

           //这个地方谢谢,可否帮我修正,谢谢了
            ctx.body=1;

        });
@egg-bot
Copy link

egg-bot commented Feb 15, 2019

Hello @xinnian1992. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@xinnian1992,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

2 similar comments
@egg-bot
Copy link

egg-bot commented Feb 15, 2019

Hello @xinnian1992. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@xinnian1992,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@egg-bot
Copy link

egg-bot commented Feb 15, 2019

Hello @xinnian1992. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@xinnian1992,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

@xinnian1992
Copy link
Author

//这是一个数据导出的功能,我需要数据导出保存为excel的时候,返回文件的路径-----谢谢

var Excel = require('exceljs');

  • excelOut() {
    var workbook = new Excel.Workbook();
    // 基本的创建信息
    workbook.creator = "Me";
    workbook.lastModifiedBy = "Her";
    workbook.created = new Date(1985, 8, 30);
    workbook.modified = new Date();
    workbook.lastPrinted = new Date(2016, 9, 27);

          // 视图大小, 打开Excel时,整个框的位置,大小
          workbook.views = [
              {
                  x: 0,
                  y: 0,
                  width: 1000,
                  height: 2000,
                  firstSheet: 0,
                  activeTab: 1,
                  visibility: "visible"
              }
          ];
    
          // 标签创建
          var worksheet = workbook.addWorksheet("第一个标签");
          // 带颜色的
          var worksheet2 = workbook.addWorksheet("第二个标签", {properties: {tabColor: {argb: "FFC0000"}}});
    
          // 遍历标签
          workbook.eachSheet((worksheet, sheetId) => {
              console.log("标签ID:", sheetId)
          })
          // console.log(worksheet);
          // 删除一个标签
          workbook.removeWorksheet(2)
    
          var firstSheet = workbook.getWorksheet(1);
          console.log("标签信息-id", firstSheet.id);
          console.log("获取总的:行/实际行 /列/实际列 个数: ", firstSheet.rowCount, firstSheet.actualColumnCount, firstSheet.columnCount, firstSheet.actualColumnCount);
    
          // 添加那个筛选箭头
          // worksheet.autoFilter = 'A1:C1';
    
          worksheet.getRow(5).font = {size: 14, bold: true};
          var letter = ["A", "B", "C"];
          worksheet.getCell("A1").value = "校区";
          worksheet.getCell("B1").value = "电话";
          worksheet.getCell("C1").value = "姓名";
    
          for (var a = 0; a < letter.length; a++) {
              worksheet.getCell(letter[a] + "1").font = {
                  name: "Arial Black",
                  // color: {argb: "FF00FF00"},
                  family: 2,
                  size: 14,
                  // italic: true,
                  bold: true
              };
          }
    
          for (var b = 2; b < 10; b++) {
              for (var c = 0; c < letter.length; c++) {
                  console.log(letter[c] + b);
                  worksheet.getCell(letter[c] + b).value = b;
              }
          }
    
          // save workbook to disk
          const ctx=this.ctx;
          workbook.xlsx.writeFile("./app/public/excel/first.xlsx").then(function () {
              console.log("saved");
    
    
             //**此处返回json**
              ctx.body=1;
          });
    
      }
    

@xinnian1992
Copy link
Author

谢谢大神

@atian25
Copy link
Member

atian25 commented Feb 15, 2019

await workbook.xlsx.writeFile("./app/public/excel/first.xlsx")

。。。 去学下 ES6 Async 等基础先吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants