Hi All, is it possible to save a report as excel?
On the desktop application, I can see we can do it manually. But how about doing it programmatically with Sage 200 SDK?
This is discussed in the SDK Help files - under 'external reporting'. You need to create a class which implements IReportingEngineHost and then pass the Report instance to it, rather than calling report.Run();.
Here's an example of such an implementation:
public class SendToExcelExample : Sage.Reporting.Engine.Integration.IReportingEngineHost { private Sage.Reporting.Engine.Integration.IReportingEngineSite _site; public SendToExcelExample() { } #region IReportingEngineHost members public IReportingEngineSite Site { get => _site; set => _site = value; } public object GetService(Guid identifier) { return null; } #endregion public bool SendReportToExcel(Sage.Accounting.Reporting.Report report, string outputFileName) { bool success = false; try { if (report.BuildFileName()) { string actualFilename = report.ActualFileName; var criteria = report.Criteria; var exportType = Sage.Reporting.Engine.Integration.ExportType.SendToExcel; Sage.Reporting.Engine.Integration.ReportingEngine reportingEngine = new Sage.Reporting.Engine.Integration.ReportingEngine(); _site = reportingEngine.CreateInstance(this); //create the export service Sage.Reporting.Engine.Integration.IExportService exporter = (Sage.Reporting.Engine.Integration.IExportService)Site.GetService (Sage.Reporting.Engine.Integration.ServiceIdentifiers.Export); exporter.Load(actualFilename); foreach (Sage.Accounting.Reporting.Criterion criterion in criteria) { if (criterion.Values != null) { exporter.Criteria.Add(criterion.Name, criterion.Values); } else { if (criterion.High != null) { exporter.Criteria.Add(criterion.Name, criterion.High); } if (criterion.Low != null) { exporter.Criteria.Add(criterion.Name, criterion.Low); } } } success = exporter.Run(exportType, outputFileName, ExportFlags.SuppressUserInteraction); } } catch { success = false; } return success; } }
And here it is in use:
Sage.Accounting.Reporting.Report report = Sage.Accounting.Application.ReportingService.CreateReport(); Sage.Accounting.Reporting.Criteria criteria = report.Criteria; Sage.Accounting.Reporting.Criterion criterion; criterion = criteria.Add(); criterion.Name = Sage.Accounting.Common.ReportingConstants.CRITERIA_SALES_BALANCE; criterion.Low = 0.00; criterion.High = 20000.00; criterion = criteria.Add(); criterion.Name = Sage.Accounting.Common.ReportingConstants.CRITERIA_SAL_TRAN_TYPE; criterion.Values = new object[] { EnumSalesTransactionType.Receipt, EnumSalesTransactionType.Payment, EnumSalesTransactionType.Invoice, EnumSalesTransactionType.CreditNote }; criterion = criteria.Add(); criterion.Name = Sage.Accounting.Common.ReportingConstants.CRITERIA_SALES_REF; criterion = criteria.Add(); criterion.Name = Sage.Accounting.Common.ReportingConstants.CRITERIA_SALES_SHORT; report.OutputMode = Sage.Accounting.Reporting.OutputModeEnum.Preview; report.FileName = @"Sales\Sales Ledger Transactions Report.report"; report.Criteria = criteria; //pass the report to the exporter class SendToExcelExample example = new SendToExcelExample(); example.SendReportToExcel(report, @"D:\MyOutputFile.xlsx");
okay noted. thank you Chris. I thought the example on the site is for pdf only
*Community Hub is the new name for Sage City