Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a Word-compatible document in the <see cref="C1Editor"/>
        /// </summary>
        /// <remarks>This method saves the file from MSWord to a temporary file, then loads it to C1Editor.</remarks>
        /// <param name="editor">Editor to </param>
        /// <param name="fileName">File name.</param>
        public static void LoadWord(this C1Editor editor, string fileName)
        {
            var app = new ApplicationClass();

            app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
            object nullobj      = Missing.Value;
            object makeFalse    = false;
            object tempFileName = Path.GetTempFileName();

            try
            {
                object fileFormt = WdSaveFormat.wdFormatFilteredHTML;
                app.Visible = false;
                var doc = app.Documents.Open(Path.GetFullPath(fileName));
                doc.WebOptions.Encoding = MsoEncoding.msoEncodingUTF8;
                foreach (InlineShape s in doc.InlineShapes)
                {
                    if (s.Type == WdInlineShapeType.wdInlineShapeLinkedPicture)
                    {
                        if (s.LinkFormat?.SourcePath != null)
                        {
                            if (s.LinkFormat.SourcePath.ToLower().Contains("ourimagesdirectory"))
                            {
                                s.LinkFormat.SavePictureWithDocument = true;
                            }
                        }
                    }
                    s.LinkFormat?.Update();
                }

                doc.SaveAs(ref tempFileName, ref fileFormt,
                           ref makeFalse, ref nullobj, ref makeFalse,
                           ref nullobj, ref nullobj, ref nullobj, ref makeFalse, ref nullobj, ref nullobj,
                           ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);


                doc.Close(ref nullobj, ref nullobj, ref nullobj);
            }
            finally
            {
                app.Quit(ref nullobj, ref nullobj, ref nullobj);
            }

            string html = File.ReadAllText((string)tempFileName);

            File.Delete((string)tempFileName);
            editor.Xml = html;
        }
Exemplo n.º 3
0
        //----------------------------------------------------------------------
        #region ** ctor

        public C1RibbonEditorXhtml(C1Editor editor)
        {
            _editor            = editor;
            _editor.AcceptsTab = true;
        }
Exemplo n.º 4
0
 public XhtmlPrintDocument(C1Editor editor)
 {
     _editor = editor;
 }