Esempio n. 1
0
        /// <summary>
        /// Get the word file format.
        /// </summary>
        /// <param name="format">The file format to save to.</param>
        /// <returns>The word file format</returns>
        private object GetWordFormat(WordFileFormat format = WordFileFormat.Original)
        {
            switch (format)
            {
            case WordFileFormat.HTML:
                return(Word.WdSaveFormat.wdFormatHTML);

            case WordFileFormat.XML:
                return(Word.WdSaveFormat.wdFormatXML);

            case WordFileFormat.RTF:
                return(Word.WdSaveFormat.wdFormatRTF);

            case WordFileFormat.PDF:
                return(Word.WdSaveFormat.wdFormatPDF);

            default:
                return(Word.WdSaveFormat.wdFormatDocument);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new template contract, no data is inserted.
        /// </summary>
        /// <param name="location">The location where the workbook is to be saved.</param>
        /// <param name="templateLocation">The workbook template location.</param>
        /// <param name="format">The file format to save to.</param>
        protected void CreateTemplate(string location, string templateLocation = "", WordFileFormat format = WordFileFormat.Original)
        {
            try
            {
                // Create a new contract
                CreateDocument(templateLocation);

                // Save the contract
                SaveDocument(location, format);
                CloseDocument();
                QuitApplication();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Document != null)
                {
                    Document = null;
                }

                if (Application != null)
                {
                    Application = null;
                }

                try
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch { }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the current document.
        /// </summary>
        /// <param name="location">The location where the document is to be saved.</param>
        /// <param name="format">The file format to save to.</param>
        protected void SaveDocument(string location, WordFileFormat format = WordFileFormat.Original)
        {
            // Get the save file format for the current document.
            object paramExportFormat = GetWordFormat(format);

            // Save the document
            _document.SaveAs(
                location,
                paramExportFormat,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing,
                ref _refMissing);
        }