public static void ExportWord(string reportID, object dataSource, List <ReportParam> reportParams, bool hasOpened = true, bool isUseParramCommon = true)
        {
            string templateName = ReportTemplate.GetTemplate(reportID);

            SaveFileDialog openFileDialog = new SaveFileDialog
            {
                Filter   = "Word Document(*.docx)|*.docx",
                FileName = templateName
            };

            string path;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                path = openFileDialog.FileName;
            }
            else
            {
                return;
            }

            try
            {
                DocxExportOptions exportOptions = new DocxExportOptions
                {
                    TableLayout   = true,
                    KeepRowHeight = true,
                };

                XtraReport report = GetReport(reportID, dataSource, reportParams, isUseParramCommon);
                if (report == null)
                {
                    return;
                }

                report.ExportToDocx(path, exportOptions);

                if (hasOpened)
                {
                    System.Diagnostics.Process.Start(path);
                }
            }
            catch (Exception ex)
            {
                BSLog.Logger.Warn(ex.Message);
                MessageBoxHelper.ShowErrorMessage($"Xuất word thất bại!\r\n{ex.Message}");
            }
        }
Example #2
0
        /// <summary>
        /// 自動發送功能
        /// </summary>
        public override void TextChange()
        {
            XtraReportSetting = InitialMethod.InitialXtraReportLoad();
            ReportTitleSetting reportTitle = InitialMethod.InitialReportTitleSetting();
            FileFormatSetting  fileFormat  = InitialMethod.InitialFileFormatSetting();

            if (XtraReportSetting.AutoExport && DateTime.Now.Day == XtraReportSetting.Day)
            {
                if (!ExportFlag)
                {
                    string ttime = string.Empty;
                    if (XtraReportSetting.Day.ToString().Length == 2)
                    {
                        ttime = DateTime.Now.ToString("yyyy/MM/") + $"{XtraReportSetting.Day} 00:00:00";
                    }
                    else
                    {
                        ttime = DateTime.Now.ToString("yyyy/MM/") + $"0{XtraReportSetting.Day} 00:00:00";
                    }
                    AnalysisXtraReport analysisXtraReport = new AnalysisXtraReport();
                    analysisXtraReport.create_XtraReport(MysqlMethod, ttime, reportTitle);
                    analysisXtraReport.CreateDocument();
                    if (Directory.Exists($"{XtraReportSetting.Path}"))
                    {
                        FileFormatTypeEnum fileFormatType = (FileFormatTypeEnum)fileFormat.FileFormat;
                        switch (fileFormatType)
                        {
                        case FileFormatTypeEnum.PDF:
                        {
                            string path = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.pdf";
                            analysisXtraReport.ExportToPdf(path);
                            break;
                        }

                        case FileFormatTypeEnum.DOCX:
                        {
                            string            path    = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.docx";
                            DocxExportOptions options = new DocxExportOptions()
                            {
                                TableLayout = true
                            };
                            analysisXtraReport.ExportToDocx(path, options);
                            break;
                        }

                        case FileFormatTypeEnum.XLSX:
                        {
                            string path = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.xlsx";
                            analysisXtraReport.ExportToXlsx(path);
                            break;
                        }
                        }
                    }
                    ExportFlag = true;
                }
            }
            else
            {
                ExportFlag = false;
            }
        }