Hướng dẫn exceljs download file - tệp tải xuống exceljs

Hướng dẫn exceljs download file - tệp tải xuống exceljs

Xin chào, tìm kiếm cùng một tính năng. Vui lòng cập nhật

Vâng, nó là có thể.

  1. Tạo sổ làm việc và điền vào nó bằng dữ liệu

  res.attachment("test.xlsx")
  workbook.xlsx.write(res)
                .then(function() {
                    res.end()
            });

Ở đây res là phản hồi cho khách hàng

Prineseth, xcyxoux, shaffron, gskjhyoo, igordevjs, rowadz, praveendev404, leonardodelira, sashuk, chenop, và 8 phản ứng , Damianchojna và 3 người khác đã phản ứng với ngón tay cái xuống Emojigskjhyoo đã phản ứng với tiếng cười biểu tượng cảm xúc đã phản ứng với Emojishaffron bối rối, Bcamargoz, GSKJHYOO và DMCGUINNESS

Xin chào, tất cả mọi người, tôi là một người mới nhất trong chủ đề này. Do đó, tôi không thể hiểu mã sau trong ví dụ: res.attachment("test.xlsx"); res trên máy khách là gì? Làm thế nào tôi có thể tạo res?
I am a newest in this topic. Thereby, I couldn't understand the following code in the example:
res.attachment("test.xlsx");
What is res on the client? How can I create res?

Cảm ơn, Paul

Tôi nghĩ rằng các bình luận trước đây có thể đã bị nhầm lẫn về những gì đang được hỏi. res cho tôi biết rằng chúng có nghĩa là một phản hồi nút được gửi lại cho máy khách. Poster ban đầu đã yêu cầu một cách để tạo và tải xuống một tệp mà không cần sử dụng máy chủ. Tôi cũng muốn chức năng này và chưa thể làm cho nó hoạt động.

Tương tự ở đây, tôi đang sử dụng Angular, tôi có tất cả những gì tôi cần ở khách hàng, sẽ thật tuyệt nếu tôi chỉ có thể tải xuống tệp ngay từ máy khách. Cho đến nay tất cả những gì tôi đã tìm thấy có "res" của nút

Xin chào, mã sau đây hoạt động với tôi: `` `JS Workbook.xlsx.writebuffer (). Sau đó (function (data) {var blob = new blob ([data], {type:" application/vnd.openxmlformats offatedocument. bảng tính.

clbcabral, xthewiz, amkoehler, fesales, andrewkittredge, dễ dàng, ketansp, macro21, sahilbhatt92, vigneshrajann Dev-Song, Amosyu2000, Jpbecotte và Alexeyjersey đã phản ứng với biểu tượng cảm xúc trái tim

Nó cũng có tác dụng với tôi. Cảm ơn rất nhiều!

Xin chào, tôi đã đính kèm một tệp zip đang hoạt động trong sự cố này: #322 Perhaby COU có thể thử điều đó? Trân trọng Manfred
I've attached one working zip file in this incident: #322 perhaby cou can try that ?
Best regards
Manfred

@Pleger bạn có ví dụ về cách tải xuống excel không? Tôi đã sử dụng res.doad tải. Nhưng vẫn không thể tải xuống tập tin. Nhưng nó có thể viết excel

Tôi hy vọng mã sau đây có thể giúp bạn!

Trích xuất từ ​​http://pleger.cl/gp

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

Nó hoạt động cho tôi

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

1

export async function download(ctx: koa.Context) {
    const workbook = new Excel.Workbook()
    const worksheet = workbook.addWorksheet("report")
    worksheet.columns = [
      {header: "Date", key: "date", width: 20}]
    ctx.response.attachment("report.xlsx")
    ctx.status = 200
    await workbook.xlsx.write(ctx.res)
    ctx.res.end()
}

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

2 Mã này cho tôi lỗi chức năng không tồn tại
this code gives me error that function not exist

Để tải xuống trên trình duyệt.

workbook.xlsx.writeBuffer().then(function (data: Blob) {
     const blob = new Blob([data],
       { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
     const url = window.URL.createObjectURL(blob);
     const anchor = document.createElement('a');
     anchor.href = url;
     anchor.download = 'download.xls';
     anchor.click();
     window.URL.revokeObjectURL(url);
   });

2012MJM, Alanwalter45, Chris-Canipe, Chris-Vecchio, Skoricit, Rene-Xompass, Vhiguita, Charlesokwuagwu, Qblua, Vladislav Phản ứng với biểu tượng cảm xúc trái tim và fairbrook đã phản ứng với biểu tượng cảm xúc tên lửa

Nó hoạt động cho tôi

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

1

export async function download(ctx: koa.Context) {
    const workbook = new Excel.Workbook()
    const worksheet = workbook.addWorksheet("report")
    worksheet.columns = [
      {header: "Date", key: "date", width: 20}]
    ctx.response.attachment("report.xlsx")
    ctx.status = 200
    await workbook.xlsx.write(ctx.res)
    ctx.res.end()
}

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

2 Mã này cho tôi lỗi chức năng không tồn tại

Để tải xuống trên trình duyệt.
res.setHeader('Content-Type', 'text/xlsx');
res.setHeader(
'Content-Disposition',
'attachment; filename=test.xlsx'
);
workbook.xlsx.write(res)
.then(function () {
res.end()
});

Để tải xuống trên trình duyệt.

workbook.xlsx.writeBuffer().then(function (data: Blob) {
     const blob = new Blob([data],
       { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
     const url = window.URL.createObjectURL(blob);
     const anchor = document.createElement('a');
     anchor.href = url;
     anchor.download = 'download.xls';
     anchor.click();
     window.URL.revokeObjectURL(url);
   });

2012MJM, Alanwalter45, Chris-Canipe, Chris-Vecchio, Skoricit, Rene-Xompass, Vhiguita, Charlesokwuagwu, Qblua, Vladislav Phản ứng với biểu tượng cảm xúc trái tim và fairbrook đã phản ứng với biểu tượng cảm xúc tên lửa

@Lihaogit Hi, Làm thế nào để nhận và biến dữ liệu thành tệp Excel khi bạn gửi dữ liệu như thế này?

Tôi hy vọng mã sau đây có thể giúp bạn!

Trích xuất từ ​​http://pleger.cl/gp

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

Nó hoạt động cho tôi
My data is coming from API but after downloading the excel the data is not having proper sequence like the data which is in column 1 of my report is now coming in column 4 and so on.

$(document).ready(function () {  
  | var workbook = new ExcelJS.Workbook();
  |  
  | workbook.creator = 'Paul Leger';
  | workbook.lastModifiedBy = 'Paul Leger';
  | workbook.created = new Date();
  | workbook.modified = new Date();
  | workbook.lastPrinted = new Date();
  |  
  | var worksheet = workbook.addWorksheet("Publications");
  | worksheet.views = [
  | {state: 'frozen', xSplit: 0, ySplit: 1}
  | ];
  |  
  | worksheet.autoFilter = {
  | from: 'A1',
  | to: 'M1'
  | };
  |  
  | worksheet.columns = [
  | { header: 'Index', key: 'Index', width: 15 },
  | { header: 'Title', key: 'title', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Authors', key: 'authors', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'Journal/Conference', key: 'jc', width: 25, style: {alignment: {wrapText: true} } },
  | { header: 'Type', key: 'type', width: 12, style: {alignment: {wrapText: true} } },
  | { header: 'Year', key: 'year', width: 12, style: {numFmt: "0000"}},
  | { header: 'Month', key: 'month', width: 12},
  | { header: 'volume', key: 'volume', width: 12},
  | { header: 'number', key: 'number', width: 12},
  | { header: 'Pages', key: 'pages', width: 12},
  | { header: 'Location', key: 'location', width: 20, style: {alignment: {wrapText: true} } },
  | { header: 'doi', key: 'doi', width: 22, style: {alignment: {wrapText: true} } },
  | { header: 'affiliation', key: 'affiliation', width: 20, style: {alignment: {wrapText: true} } }
  | ];
  |  
  | var firstRow = worksheet.getRow(1);
  | firstRow.font = { name: 'New Times Roman', family: 4, size: 10, bold: true, color: {argb:'80EF1C1C'} };
  | firstRow.alignment = { vertical: 'middle', horizontal: 'center'};
  | firstRow.height = 20;
  |  
  |  
  | csv.shift();
  | worksheet.addRows(csv);
  |  
  | var buff = workbook.xlsx.writeBuffer().then(function (data) {
  | var blob = new Blob([data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
  | saveAs(blob, "publications.xlsx");
  | });

2 Mã này cho tôi lỗi chức năng không tồn tại
generateExcel(){
this._http.generateExcel(this.headerInfo, this.spendclassificationlist);
}

Để tải xuống trên trình duyệt.