Example #1
0
        /// <summary>
        /// Writes data contained in ADO.NET DataTable object to path stored in OutputFileName property.
        /// </summary>
        /// <param name="dt">DataTable object containing data to be output.</param>
        /// <returns>True if output operation is successful. False if write fails.</returns>
        public bool WriteDataToOutput(DataTable dt)
        {
            bool           success = true;
            PFWordDocument docOut  = null;

            try
            {
                if (File.Exists(_outputFileName))
                {
                    if (_replaceExistingFile)
                    {
                        File.SetAttributes(_outputFileName, FileAttributes.Normal);
                        File.Delete(_outputFileName);
                    }
                    else
                    {
                        _msg.Length = 0;
                        _msg.Append("File exists and ReplaceExistingFile set to False. Write to Output has failed.");
                        throw new System.Exception(_msg.ToString());
                    }
                }

                enWordOutputFormat outputFormat = this.WordVersion == enWordVersion.Word2007 ? enWordOutputFormat.Word2007 : enWordOutputFormat.Word2003;
                docOut = new PFWordDocument(outputFormat, this.OutputFileName, this.ReplaceExistingFile);
                docOut.WriteDataToDocument(dt);
            }
            catch (System.Exception ex)
            {
                success     = false;
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                throw new System.Exception(_msg.ToString());
            }
            finally
            {
                if (docOut != null)
                {
                    docOut = null;
                }
            }

            return(success);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="wordOutputFormat">Set to PFWordInterop.Word2003 for an XLS file. Set to PFWordInterop.Word2007 for an XLSX file.</param>
 /// <param name="documentFilePath">Full path to the output file.</param>
 /// <param name="replaceExistingFile">True to overwrite existing file with same name. Otherwise, set to false to throw an error if file with same name already exists.</param>
 public PFWordInterop(enWordOutputFormat wordOutputFormat, string documentFilePath, bool replaceExistingFile)
 {
     _wordOutputFormat    = wordOutputFormat;
     _documentFilePath    = documentFilePath;
     _replaceExistingFile = replaceExistingFile;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="wordOutputFormat">Set to PFWordInterop.Word2003 for an XLS file. Set to PFWordInterop.Word2007 for an XLSX file.</param>
 public PFWordInterop(enWordOutputFormat wordOutputFormat)
 {
     _wordOutputFormat = wordOutputFormat;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="wordOutputFormat">Set to PFWordInterop.Word2003 for an XLS file. Set to PFWordInterop.Word2007 for an XLSX file.</param>
 /// <param name="documentFilePath">Full path to the output file.</param>
 public PFWordInterop(enWordOutputFormat wordOutputFormat, string documentFilePath)
 {
     _wordOutputFormat = wordOutputFormat;
     _documentFilePath = documentFilePath;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="wordOutputFormat">Set to enWordOutputFormat.Word2003 for an XLS file. Set to enWordOutputFormat.Word2007 for an XLSX file.</param>
 public PFWordDocument(enWordOutputFormat wordOutputFormat)
 {
     _wordOutputFormat = wordOutputFormat;
 }