μλ νμΈμ,
@sendgrid/mail - "^6.3.1" λ° λ Έλ - 10.14.1μ μ¬μ©νκ³ μμ΅λλ€.
λ΄ λ¬Έμ λ Excel μ²¨λΆ νμΌμ λ°μ΄ν°λ² μ΄μ€μμ λ¨μΌ ν λ°μ΄ν°λ₯Ό λ³΄λΌ λ μ²¨λΆ νμΌμ΄μλ λ©μΌμλ°μ μ μμ§λ§ Excelμ λ°μ΄ν°λ² μ΄μ€ λ°μ΄ν°μμ μ¬λ¬ ν λ°μ΄ν°λ₯Ό μ²¨λΆ νμΌλ‘ λ³΄λΌ λ 0 λ°μ΄νΈμ μ²¨λΆ νμΌμ μμ νλ€λ κ²μ
λλ€. νμΌμ μ΄λ―Έμ§λ ν¬ν¨μμΌ°μ΅λλ€. Exceljs λͺ¨λμ ν΅ν΄ μμ±ν λμΌν νμΌμ 첨λΆνλ €κ³ ν©λλ€. IIλ λ§μ΄ μλνμ§λ§ μ€ν¨νμ΅λλ€ .. λΈλΌμ°μ μμ μ΄ μ½λλ₯Ό μ¬μ©νμ¬ λμΌν Excel νμΌμ μμ±ν μ μλ κ³³μμ
"
res.setHeader("μ½ν
μΈ μ ν", "μμ© νλ‘κ·Έλ¨/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
res.setHeader("λ΄μ© μ²λ¦¬", "μ²¨λΆ νμΌ μ΄λ¦='" + excelFile.excelOffFile + "'");
workbookFinal.xlsx.write(res).then(() => {
res.end(); });μμ€
"
λ©μΌμ 보λ΄κΈ° μν λ΄ μ½λλ -
sgMail.send({
λ°λ μ¬λ: config.get("mail.defaultAdd"),
λ³΄λΈ μ¬λ: fromMailμΆκ°,
μ λͺ©: "μμ
μ²¨λΆ μ£Όλ¬Έ μννΈμ¨μ΄λ₯Ό ν΅ν΄ 보λ΄κΈ°",
HTML: <h1>Test Mail</h1>
,
μ²¨λΆ νμΌ: [
{
λ΄μ©: fs.readFileSync(excelFile.excelOffFilePath, {μΈμ½λ©:"base64"}),
νμΌ μ΄λ¦: excelFile.excelOffFile,
μ ν: "μμ© νλ‘κ·Έλ¨/vnd.ms-excel"
},
{
λ΄μ©: fs.readFileSync(excelFile.excelFactFilePath, { μΈμ½λ©: "base64" }),
νμΌ μ΄λ¦: ExcelFile.excelFactFile,
μ ν: "μμ© νλ‘κ·Έλ¨/vnd.ms-excel"
},
{
λ΄μ©: fs.readFileSync(excelFile.excelBrFilePath, { μΈμ½λ©: "base64" }),
νμΌ μ΄λ¦: ExcelFile.excelBrFile,
μ ν: "μμ© νλ‘κ·Έλ¨/vnd.ms-excel"
},
{
λ΄μ©: fs.readFileSync(excelFile.excelSuFilePath, { μΈμ½λ©: "base64" }),
νμΌ μ΄λ¦: excelFile.excelSuFile,
μ ν: "μμ© νλ‘κ·Έλ¨/vnd.ms-excel"
}
]
})
λ©μΌ μ€ν¬λ¦°μ· -
κ°μ λ¬Έμ λ₯Ό ν΄κ²°νλ λ°©λ²μ λμμ£ΌμΈμ.
μλ νμΈμ @prasoojalan μ λλ€ .
νμΌ κ²½λ‘λ νμΌ μΈμ½λ©μ λ¬Έμ κ° μλ κ² κ°μ΅λλ€. νμΌμ΄ μ‘΄μ¬νλμ§ νμΈνκΈ° μν΄ μ½λμμ excelFile.*
κ°μ λ€μ νμΈν©λλ€. κ·Έλ° λ€μ νμΌ μμ²΄κ° base64λ‘ μ¬λ°λ₯΄κ² μΈμ½λ©λμλμ§ νμΈν©λλ€. μ΄μ©λ©΄ μ΄ λꡬ κ° νμλ₯Ό λμΈ μ μμ΅λλ€.
λ§μμ λ΄μ,
μλ¨Έ
μλ νμΈμ @ μλ¨Έ
νμΌ μμ± λ° μ μ‘μ μν λ΄ μ 체 μ½λλ λ€μκ³Ό κ°μ΅λλ€.
νλμ μ²¨λΆ λ£¨νΈ κ²½λ‘λ₯Ό μ 곡νλ €κ³ μλνμ§λ§ μλνμ§ μμμ΅λλ€. μμ±λ λμΌν μμ
νμΌμ΄ λΈλΌμ°μ μ μ±κ³΅μ μΌλ‘ λ€μ΄λ‘λλμμ΅λλ€.... μ΄λ€ μ½λκ° λλ½λμκ±°λ κ°λ
μ μ λλ‘ μ΄ν΄ν μ μμ΅λλ€... λμμ£Όμ€ μ μλμ?
"C"λ₯Ό λ§€κ° λ³μλ‘ μ¬μ©νλ createExcelFile ν¨μμμ λ€λ₯Έ κ²½μ°μλ μλ ν΅ν© λ¬Έμλ₯Ό λ°νν©λλ€.
exports.getExcelFile = (req, res, next) => {
const excelFile = {};
Order.findById(req.params.id).then(order => {
excelFile.excelOffFile = "Off_" + order.factory + "_" + order._id + ".xls";
excelFile.excelOffFilePath = path.join("data", "excel", excelFile.excelOffFile);
excelFile.excelFactFile = "Fact_" + order.factory + "_" + order._id + ".xls";
excelFile.excelFactFilePath = path.join("data", "excel", excelFile.excelFactFile);
excelFile.excelBrFile = "Br_" + order.factory + "_" + order._id + ".xls";
excelFile.excelBrFilePath = path.join("data", "excel", excelFile.excelBrFile);
excelFile.excelSuFile = "Su_" + order.factory + "_" + order._id + ".xls";
excelFile.excelSuFilePath = path.join("data", "excel", excelFile.excelSuFile);
let workbookFinal = createExcelFile(order, "C", excelFile.excelOffFilePath);
createExcelFile(order, "F", excelFile.excelFactFilePath);
createExcelFile(order, "B", excelFile.excelBrFilePath);
createExcelFile(order, "S", excelFile.excelSuFilePath);
sgMail.send({
to: config.get("mail.defaultAdd"),
from: defaultMailId,
subject: "Order with excel attachment send through software ",
html: `<h1>
The mail has been sent as trial through program for testing excel file attachement .
</h1>
<h3>
Office file - ${url.format({ protocol: req.protocol, host: req.get("host"), pathname: "orders/genExcelFile/" + excelFile.excelOffFile })}</br>
Fact file - ${url.format({ protocol: req.protocol, host: req.get("host"), pathname: "orders/genExcelFile/" + excelFile.excelFactFile })}</br>
Br file - ${url.format({ protocol: req.protocol, host: req.get("host"), pathname: "orders/genExcelFile/" + excelFile.excelBrFile })}</br>
Su file - ${url.format({ protocol: req.protocol, host: req.get("host"), pathname: "orders/genExcelFile/" + excelFile.excelSuFile })}</br>
</h3>
`,
attachments: [
{
content: fs.readFileSync(path.join(rootDir.rootDir, excelFile.excelOffFilePath), { encoding: "base64" }),
filename: excelFile.excelOffFile,
},
{
content: fs.readFileSync(excelFile.excelFactFilePath, { encoding: "base64" }),
filename: excelFile.excelFactFile,
},
{
content: fs.readFileSync(excelFile.excelBrFilePath, { encoding: "base64" }),
filename: excelFile.excelBrFile,
},
{
content: fs.readFileSync(excelFile.excelSuFilePath, { encoding: "base64" }),
filename: excelFile.excelSuFile,
}
]
}).then(result => {
console.log("mail sent successfully...");
}).catch(err => console.log(err));
res.setHeader("Content-Type", "application/vnd.ms-excel");
res.setHeader("Content-Disposition", "attachment;filename='" + excelFile.excelOffFile + "'");
workbookFinal.xlsx.write(res).then(() => {
res.end();
});
}).catch(err => console.log(err));
};
μλ νμΈμ @Elmer
λΉμ μ μ μμ κ°μ¬λ립λλ€. μ λ₯Ό λ§μ΄ λΉν©νκ² νλ μ½λμ νλ¦μ μ΄ν΄νλ λ° λμμ΄ λμμ΅λλ€.
λλ λ΄ μ€μλ₯Ό νμ
νκ³ ν΄κ²°νμ΅λλ€. λ΄ μ½λλ λ©μΌμ λ³΄λΌ λ κΈ°λ‘μ΄ μλ Excel νμΌμ μμ±νμ΅λλ€. κ·Έλμ ν¨μμμ λ©μΌ μ½λλ₯Ό μ κ±°νκ³ λ³λμ ν¨μλ₯Ό λ§λ λ€μ getExcelFile ν¨μ λ€μμ ν¨μλ₯Ό νΈμΆνμ΅λλ€. μ΄λ κ² νλ©΄ νμΌμ΄ μμ±λκ³ νμΌμ΄ μ¬λ°λ₯΄κ² 첨λΆλμμμ νμΈν μ μμμ΅λλ€.
μΆκ° μ§λ¬Έμ μ κΈ°νκΈ° μ μ μ μ½λμ μ§μ€ν μ μλλ‘ λμμ£Όμ μ λ€μ ν λ² μ§μ¬μΌλ‘ κ°μ¬λ립λλ€.
λ§μμ λ΄μ,
νλΌμ μΏ λ§λ₯΄ μλ