我们最近发布了一篇关于使用Quartz.NET 库自动执行报告任务的文章。继续这个主题,今天我们将深入探讨我们的报告如何与 Node Schedule 作业调度程序集成。
Stimulsoft Ultimate (原Stimulsoft Reports.Ultimate)是用于创建报表和仪表板的通用工具集。该产品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他环境的完整工具集。无需比较产品功能,Stimulsoft Ultimate包含了所有内容!
Stimulsoft Reports官方正版下载(qun:585577353)
https://www.evget.com/product/2398/download
什么是节点计划?
Node Schedule 是 Node.js 的灵活作业调度程序,按 cron 语法运行。它执行任务,允许基于时间而不是间隔的可选重复规则。节点计划可用于各种目的,例如发送报告电子邮件、进行例行数据库维护或执行定期数据分析任务。
开始一个项目
我们的第一步是在 JavaScript 平台上建立一个项目。为此,我们将使用JS 报告工具(完全用 JavaScript 开发的各种报告组件)。通过简单安装相应的npm 包,可以将该工具集成到自定义应用程序中。
安装软件包
要使用报告,我们需要stimulsoft-reports-js包,对于仪表板 - stimulsoft-dashboards-js。
此外,要添加和使用调度程序,您应该安装Node Schedule包。
定义任务并设置时间表
让我们直接进入本文的要点。我们选择将报告导出为 PDF 作为示例任务。接下来,我们将导出配置为每天 10:00 执行。
// Node Schedule module
var schedule = require("node-schedule");
console.log("Node Schedule loaded");
// Stimulsoft Reports module
var Stimulsoft = require("stimulsoft-reports-js");
console.log("Stimulsoft Reports loaded");
// Creating new report
var report = new Stimulsoft.Report.StiReport();
console.log("New report created");
// Loading report template
report.loadFile("SimpleList.mrt");
console.log("Report template loaded");
// Run the task every day at 10:00
var rule = new schedule.RecurrenceRule();
rule.hour = 10;
rule.minute = 0;
console.log("Rule for the task created");
// Scheduling the task
schedule.scheduleJob(rule, function () {
// Renreding report
report.renderAsync(() => {
console.log("Report rendered. Pages count: ", report.renderedPages.count);
// Export to PDF
report.exportDocumentAsync((pdfData) => {
// Converting Array into buffer
var buffer = Buffer.from(pdfData);
// File System module
var fs = require("fs");
// Saving string with rendered report in PDF into a file
fs.writeFileSync("./SimpleList.pdf", buffer);
console.log("Rendered report saved into PDF-file.");
}, Stimulsoft.Report.StiExportFormat.Pdf);
});
});
我们通过一个例子演示了自动化过程。从现在起,报告将在每天 10:00 转换为 PDF 文件并保存到磁盘。



















