コード例 #1
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in DocumentFilePath property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be imported.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        public bool WriteDataToDocument(DataTable dt)
        {
            bool          success = true;
            PFWordInterop wordDoc = null;

            try
            {
                wordDoc = new PFWordInterop(enWordOutputFormat.RTF, this.DocumentFilePath, this.ReplaceExistingFile);
                success = wordDoc.WriteDataToDocument(dt);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append("Attempt to import DataTable into RTF document failed. ");
                _msg.Append(Environment.NewLine);
                _msg.Append(PFTextProcessor.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (wordDoc != null)
                {
                    wordDoc = null;
                }
            }

            return(success);
        }
コード例 #2
0
        public void OutputToWordDocument(MainForm frm)
        {
            PFWordInterop wordDoc = null;
            DataSet       ds      = null;

            try
            {
                _msg.Length = 0;
                _msg.Append("OutputToWordDocument started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                ds = new DataSet();
                ds.ReadXml(@"C:\Testfiles\C1Testing\RandomNames100Lines.xml");
                ds.Tables[0].TableName = "RandomNames";

                if (frm.optDOCXFormat.Checked)
                {
                    wordDoc = new PFWordInterop(enWordOutputFormat.Word2007, @"c:\temp\WordInteropRandomNames.docx", true);
                }
                else if (frm.optDOCFormat.Checked)
                {
                    wordDoc = new PFWordInterop(enWordOutputFormat.Word2003, @"c:\temp\WordInteropRandomNames.doc", true);
                }
                else if (frm.optRTFFormat.Checked)
                {
                    wordDoc = new PFWordInterop(enWordOutputFormat.RTF, @"c:\temp\WordInteropRandomNames.rtf", true);
                }
                else if (frm.optPDFFormat.Checked)
                {
                    wordDoc = new PFWordInterop(enWordOutputFormat.PDF, @"c:\temp\WordInteropRandomNames.pdf", true);
                }
                else
                {
                    wordDoc = new PFWordInterop(enWordOutputFormat.Word2007, @"c:\temp\WordInteropRandomNames.docx", true);
                }


                wordDoc.WriteDataToDocument(ds.Tables[0]);
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... OutputToWordDocument finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }