Каким образом можно осуществить печать пользовательского отчета в фоновом режиме, не открывая сформированный документ Word?
Нравится
Можно поступить следующим образом:
1. Добавить в функцию ShowWordReport скрипта scr_UserReportCommon дополнительный параметр с названием WithoutShow.
2. Изменить текст данной функции примерно таким образом:
function ShowWordReport(UserReportData, WorkspaceRecordIDs, WorkspaceWindow, WithoutShow) { System.BeginProcessing(); var Document; var Document = GetInitializedApplicationTemplateByReportID( UserReportData.ReportID); if (!Document) { System.EndProcessing(); UserReportCommon.ExcelReportXMLStorage = null; return null; } DisablePluginEvents(); var Caption = FormatStr(ccPercentCompleted, 0); try { var ProgressWindow = BeginProcessingProgress(WorkspaceWindow, Caption, ccWordProgressBarCaption, true); if (IsCustomDocumentPropertyExists(Document, cdpReportID)) { Document.CustomDocumentProperties(cdpReportID).Delete(); } var Application = Document.Application; SetCustomDocumentFileIDProperty(Document); var RootSection = GetRootSection(UserReportData); var Sections = UserReportData.Sections; var IsPreview = UserReportData.IsPreview; ProcessWordReportDataFill(Document, RootSection, Sections, IsPreview, WorkspaceRecordIDs, WorkspaceWindow); } finally { EnablePluginEvents(); System.EndProcessing(); var ProgressWindow = EndProcessingProgress(WorkspaceWindow, true); ProgressWindow.Attributes('CancelledByUser') = false; if (WithoutShow) { var FileNameValue = System.CreateObject('TSObjectLibrary.Value'); var FileExt = '.doc'; if (Number(Application.Version) >= 12) { FileExt = '.docx'; } if (!System.SaveDialog(FileNameValue ,"Файл" + ' Microsoft Word (*' + FileExt + ')|*' + FileExt + '|' + "Все файлы" + ' (*.*)|*.*' , FileExt , "Сохранить в файл" , Connector.WorkingDirectory)) { Application.Quit(); return; } var FileName = FileNameValue.Value; Document.SaveAs(FileName); Application.Quit(); return; } else { Document.ActiveWindow.Visible = true; Document.Activate(); var Statistic = 2; var PageNum = Document.ComputeStatistics(Statistic); var Browser = Document.Application.Browser; if (Browser) { Browser.Target = 1; for (var i = 0; i < PageNum; i++) { Browser.Previous(); } } UserReportCommon.ExcelReportXMLStorage = null; } } return Document; }
При этом, если нет необходимости вызывать диалог для выбора имени файла (путь и имя файла заранее известно), блок if (!System.SaveDialog(...)) {...} можно заменить на соответствующее имя файла.
3. При формировании отчёта, который необходимо сразу сохранять, необходимо вызывать функцию ShowWordReport с параметром WithoutShow, равным true. Например:
ShowWordReport(UserReportData, WorkspaceRecordIDs, WorkspaceWindow, true);
Олег Лабьяк,
инженер-программист,
Группа компаний Terrasoft.