StiReport report = new StiReport();
report.ReportCacheMode = StiReportCacheMode.On;
report.Load(path);
In this scenario, report caching will not be enabled, and here is why: The required ReportCacheMode property, like most report properties, is saved in the report template. Therefore, any value set before loading the report will be overwritten by the value from the template. StiReport report = new StiReport();
report.Load(path);
report.ReportCacheMode = StiReportCacheMode.On;
var settings = new StiWord2007ExportSettings();
settings.EncryptionPassword = "123456";
report.ExportDocument(StiExportFormat.Word2007, "Report.docx", settings);
Code used in our products AFTER version 2024.2.1
var settings = new StiWordExportSettings();
settings.EncryptionPassword = "123456";
report.ExportDocument(StiExportFormat.Word, "Report.docx", settings);
var settings = new StiWord2007ExportSettings();
settings.RestrictEditing = StiWord2007RestrictEditing.ExceptEditableFields;
settings.ProtectionPassword = "123456";
report.ExportDocument(StiExportFormat.Word2007, "Report.docx", settings);
Code used in our products AFTER version 2024.2.1
var settings = new StiWordExportSettings();
settings.RestrictEditing = StiWordRestrictEditing.ExceptEditableFields;
settings.ProtectionPassword = "123456";
report.ExportDocument(StiExportFormat.Word, "Report.docx", settings);
If you have any inquiries or require assistance regarding the process of protecting MS Office documents within Stimulsoft products, please do not hesitate to reach out to us. We are here to provide guidance and support to ensure your documents remain secure.
StiOptions.Engine.CheckForEmptyNestedDetail=false
{
event: "PrepareVariables",
sender: "Report",
report: StiReport,
preventDefault: boolean,
async: boolean,
variables: []
}
An example of replacing a value in a report variable:
report.onPrepareVariables = (args, callback) => {
args.variables[0].value = "Replace value";
}
{
sender: "Report",
event: "BeginProcessData",
report: StiReport,
preventDefault: boolean,
async: boolean,
command: string,
database: string,
connection: string,
headers: [],
withCredentials: string,
// Json
pathData: string,
tryParseDateTime: boolean,
relationDirection: StiRelationDirection,
// Xsd
pathSchema: string,
// Xml
pathData: string,
tryParseDateTime: boolean,
relationDirection: StiRelationDirection,
// Excel
pathData: string,
firstRowIsHeader: boolean,
// OData
connectionString: string,
dataSource: string,
collectionName: string,
// Sql
connectionString: string,
dataSource: string,
queryString: string,
timeout: number,
parameters: { name: string, value: string | number }[],
escapeQueryParameters: boolean,
// Gis
pathData: string,
separator: string,
dataType: StiGisDataType,
// Csv
pathData: string,
separator: string,
codePage: number,
// DBase
pathData: string,
codePage: number
}
Below is an example of replacing a connection string:
report.onBeginProcessData = (args) => {
if (args.database == "MySQL")
args.connectionString = "new connection string";
}
And also, here is an example of our own implementation of data retrieval:
report.onBeginProcessData = (args, callback) => {
if (args.database == "MySQL"){
args.preventDefault = true;
var result = {
success: true,
rows: [
["value1", 1, false],
["value2", 1, true],
["value3", 2, false]
],
columns: [
"Column1_name",
"Column2_name",
"Column3_name"
],
types:[
"string",
"int",
"boolean"
]
}
// https://github.com/stimulsoft/DataAdapters.JS/
callback(result);
}
}
{
sender: "Report",
event: "EndProcessData",
report: StiReport,
command: string,
dataSource: string,
connection: string,
database: sgtring,
result: DataSet|any
}
An example of adjusting data from the adapter:
report.onEndProcessData = (args) => {
if (args.command == "ExecuteQuery" && args.dataSource == "Categories")
args.result.rows.push(rowData) ;
// https://github.com/stimulsoft/DataAdapters.JS/
}
report.onBeginRender = function (args) {
const text = this.pages.getByIndex(0).components.getByIndex(0);
const newValue = report.dictionary.variables.getByName("Variable2").value;
text.text = newValue;
}
report.onRendering = function (args) {
const components = this.pages.getByIndex(0).components.list;
for (let component of components) {
if (component instanceof Stimulsoft.Report.Components.StiText) {
const num = Number.parseFloat(component.text);
if (!isNaN(num)) {
component.text = String(num * 100);
} else {
console.log("The value is NaN");
}
}
}
}
report.onEndRender = (args) => {
report.exportDocumentAsync(function (data) {
Stimulsoft.System.StiObject.saveAs(data, "Report.pdf", "application/pdf");
}, Stimulsoft.Report.StiExportFormat.Pdf);
}
report.onExporting = (args) => {
console.log("The report is complected for exporting to ${args.exportFormat");
}
report.onExported = (args) => {
const pages = report.renderedPages.list;
console.log("PDF file contains " + pages.length + " pages");
}
report.onExported = (args) => {
const pages = report.renderedPages.list;
console.log("PDF file contains " + pages.length + " pages");
}
{
sender: "Report",
event: "PrintReport",
report: StiReport,
preventDefault: boolean,
async: boolean,
data: string | number[]
}
An example of interrupting execution and implementing your own printing method:
report.onPrintReport = (args) => {
args.preventDefault = true;
var printData = args.data;
myPrintingMethod(printData);
}
StiDesignerRibbonType.DefaultRibbonType = StiDesignerRibbonType.SingleLine;
- In the reporting tool for Windows Forms applications:StiOptions.Designer.Ribbon.RibbonLayoutType = StiRibbonLayoutType.SingleLine;
- In the reporting tool for JavaScript applications:designerOptions.appearance.defaultRibbonType = StiDesignerRibbonType.SingleLine;
Note!public class StiReportJob : IJob
{
public async Task Execute(IJobExecutionContext context)
{
var report = CreateReport();
await SendEmail(report);
}
private StiReport CreateReport()
{
var report = new StiReport();
// report.Load();
return report;
}
private async Task SendEmail(StiReport report)
{
using (MailMessage mail = new MailMessage("admin@gmail.com", "user@gmail.com"))
{
mail.Subject = "New Report";
mail.Body = "Body Info";
using var stream = new MemoryStream();
report.ExportDocument(StiExportFormat.Pdf, stream);
stream.Position = 0;
var attachment = new Attachment(stream, "report.pdf", "application/pdf");
mail.Attachments.Add(attachment);
using var client = new SmtpClient
{
EnableSsl = true,
Host = "host.com",
Port = 25,
};
await client.SendMailAsync(mail);
}
}
}
public class StiJobScheduler
{
public static async void Start()
{
var scheduler = await StdSchedulerFactory.GetDefaultScheduler();
await scheduler.Start();
var job = JobBuilder.Create<StiReportJob>().Build();
var trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithCronSchedule($"0 0 10 ? * *")//At 10:00 AM
.Build();
await scheduler.ScheduleJob(job, trigger);
}
}
StiJobScheduler.Start();