Exemple #1
0
        /// <summary>
        /// Loads a Word-compatible document in the <see cref="C1Editor"/>
        /// </summary>
        /// <remarks>This method uses clipboard copy-from-MSWord paste-to-C1Editor approach.</remarks>
        /// <param name="editor">Editor to </param>
        /// <param name="fileName">File name.</param>
        public static void LoadWordClipboard(this C1Editor editor, string fileName)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File not found", fileName);
            }

            //save clipboard for further restoring
            IDataObject dataObject = BackupClipboard();

            object nullobj = Missing.Value;
            var    app     = new ApplicationClass();

            try
            {
                app.Visible = false;
                var doc = app.Documents.Open(Path.GetFullPath(fileName));


                doc.ActiveWindow.Selection.WholeStory();
                doc.ActiveWindow.Selection.Copy();

                editor.SelectAll();
                editor.Paste();

                doc.Close(ref nullobj, ref nullobj, ref nullobj);
            }
            finally
            {
                app.Quit(ref nullobj, ref nullobj, ref nullobj);
                RestoreClipboard(dataObject);
            }
        }
Exemple #2
0
 /// <summary>
 /// Pastes the contents of the Clipboard into the editor
 /// </summary>
 /// <param name="plainText">If true, pastes text only</param>
 internal void Paste(bool plainText)
 {
     if (plainText)
     {
         // paste as plain text
         _editor.PasteAsText();
     }
     else
     {
         // automatically select format
         _editor.Paste();
     }
 }