Ejemplo n.º 1
0
        public static void Generate(Report report, string fileSaveDirectory, Application app)
        {
            // generates the report in the specified reportFormat with the
            // specified report.Filename saves it in fileSaveDirectory and always overwrites it
            string cleanFilename = report.Filename.TrimStart('\\');
            string cleanPath     = fileSaveDirectory.TrimEnd('\\');

            // gen up the Word objects we need
            Document  document = app.Documents.Add();
            Paragraph paragraph;

            // load our styles into the document
            ReportCommon.LoadDocumentStyles(document);

            try
            {
                // build the report document

                // add header
                // get a handle to the first paragraph
                paragraph = document.Paragraphs[document.Paragraphs.Count];
                paragraph.set_Style(document.Styles["Header"]);
                paragraph.Range.Text  = "Sample Report";
                paragraph.Range.Text += "Header";

                // add body
                // add paragraph and get a handle to the paragraph
                document.Paragraphs.Add();
                paragraph = document.Paragraphs[document.Paragraphs.Count];
                paragraph.set_Style(document.Styles["CustomStyle"]);
                paragraph.Range.Text = "Report Body";

                // save the document
                document.SaveAs2(Path.Combine(cleanPath, cleanFilename) + "." + report.Extension, report.SaveFormat);
            }
            catch (Exception e)
            {
                throw new Exception("SampleReport.Generate: " + e.Message);
            }
            finally
            {
                // close and dispose of the writer if it exists
                document.Close(WdSaveOptions.wdDoNotSaveChanges);
            }
        } // Generate
        public static void Generate(Report report, string fileSaveDirectory, Application app)
        {
            // generates the report in the specified reportFormat with the
            // specified report.Filename saves it in fileSaveDirectory and always overwrites it
            string saveFilename = Path.Combine(fileSaveDirectory.TrimEnd('\\'), report.Filename.TrimStart('\\')) + "." + report.Extension;
            // gen up the Word objects we need
            Document document = app.Documents.Add();

            // load our styles into the document
            ReportCommon.LoadDocumentStyles(document);

            try
            {
                // build the report document
                // set the document properties
                ReportCommon.SetDocumentDefaultProperties(document, app);
                // add header
                AddDocumentHeader(document);
                // add body
                AddDocumentBody(document);
                // save the document
                document.SaveAs2(saveFilename, report.SaveFormat);
                // display ready message
                AppCommon.Log(report.Name + " ready. Open at: " + AppCommon.BuildUrl(AppCommon.GetAppEngineUrl(), report.Filename + "." + report.Extension, AppCommon.GetAppEnginePort()) + " .", EventLogEntryType.Information);
            }
            catch (Exception e)
            {
                string message = AppCommon.AppendInnerExceptionMessages("LoadsIndexViewReport.Generate: " + e.Message, e);
                message += " - Filename = " + saveFilename + "";
                throw new Exception(message);
            }
            finally
            {
                // close and dispose of the writer if it exists
                document.Close(WdSaveOptions.wdDoNotSaveChanges);
            }
        } // Generate