protected void CopyFromClipbordInlineShape()
 {   
     InlineShape inlineShape = m_word.ActiveDocument.InlineShapes[m_i];
     inlineShape.Select();
     m_word.Selection.Copy();
     Computer computer = new Computer();
     //Image img = computer.Clipboard.GetImage();
     if (computer.Clipboard.GetDataObject() != null)
     {
         System.Windows.Forms.IDataObject data = computer.Clipboard.GetDataObject();
         if (data.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap))
         {
             Image image = (Image)data.GetData(System.Windows.Forms.DataFormats.Bitmap, true);                
             image.Save(Server.MapPath("~/ImagesGet/image.gif"), System.Drawing.Imaging.ImageFormat.Gif);
             image.Save(Server.MapPath("~/ImagesGet/image.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
           
         }
         else
         {
             LabelMessage.Text="The Data In Clipboard is not as image format";
         }
     }
     else
     {
         LabelMessage.Text="The Clipboard was empty";
     }
 }
    protected void CopyFromClipboardInlineShape()
    {
        InlineShape inlineShape = m_word.ActiveDocument.InlineShapes[m_i];

        inlineShape.Select();
        m_word.Selection.Copy();
        Computer computer = new Computer();
        Image    img      = computer.Clipboard.GetImage();
        /*...*/
    }
Esempio n. 3
0
        public void insert(object aFileName, string aPicName, string aBookMark)
        {
            Microsoft.Office.Interop.Word.Application worldApp = new Microsoft.Office.Interop.Word.Application();

            Microsoft.Office.Interop.Word.Document doc = null;
            object oMissing = System.Reflection.Missing.Value;

            doc = worldApp.Documents.Open(ref aFileName,
                                          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                          ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            try
            {
                                //定义该插入图片是否为外部链接
                                object linkToFile = false;
                                //定义插入图片是否随word文档一起保存
                                object saveWithDocument = true;

                //图片
                string replacePic = aPicName;
                if (doc.Bookmarks.Exists(aBookMark) == true)
                {
                    object bookMark = aBookMark;
                                        //查找书签
                                        doc.Bookmarks.get_Item(ref bookMark).Select();

                                        //设置图片位置
                                        worldApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

                    //在书签的位置添加图片
                    InlineShape inlineShape = worldApp.Selection.InlineShapes.AddPicture(replacePic, ref linkToFile, ref saveWithDocument, ref oMissing);
                                        //设置图片大小
                                        inlineShape.Width = 100;
                    inlineShape.Height = 100;
                    inlineShape.Select();
                    inlineShape.ConvertToShape().IncrementLeft(-60.0f);


                    //将图片设置浮动在文字上方
                    inlineShape.ConvertToShape().WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapFront;
                }
            }
            catch
            {
                doc.Saved = false;
                                //word文档中不存在该书签,关闭文档
                                doc.Close(ref oMissing, ref oMissing, ref oMissing);
            }
        }
Esempio n. 4
0
        private void buttonImportFromDoc_Click(object sender, EventArgs e)
        {

            object filename = @"C:\source\repos\MyExam\MyExam\Resources\Exam PL-900 PowerApps.docx";

            Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();

            object readOnly = false;
            object isVisible = true;
            object missing = System.Reflection.Missing.Value;

            try
            {
                doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref isVisible, ref missing, ref missing, ref missing);

                Image[] images = new Image[AC.ActiveDocument.InlineShapes.Count];

                for (int i = 0; i < AC.ActiveDocument.InlineShapes.Count; i++)
                {
                    int m_i = i + 1;
                    InlineShape inlineShape = AC.ActiveDocument.InlineShapes[m_i];
                    inlineShape.Select();
                    AC.Selection.Copy();
                    Computer computer = new Computer();
                    images[i] = computer.Clipboard.GetImage();
                }

                ucXmlRichTextBoxQA.Xml = System.IO.File.ReadAllText(generateQAXMLforExam_PL_900_for_Import_docx(Regex.Replace(doc.Content.Text, @"\r\n?|\n?|\v?|\f", ""), images));               


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error is occured", MessageBoxButtons.OK);
            }
            finally
            {
                object doNotSaveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                doc.Close(ref doNotSaveChanges, ref missing, ref missing);
                AC.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(doc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(AC);
                GC.Collect();
            }           
        }
Esempio n. 5
0
        /// <summary>
        /// 复制其他文件的文本框到当前word
        /// </summary>
        /// <returns></returns>
        public string CopyImageToWord(string otherFilePath, string bookmark, bool isCloseTheFile)
        {
            try
            {
                Document otherFile = OpenWord(otherFilePath);
                otherFile.Select();

                Range bookmarkPic = GetBookmarkRank(_currentWord, bookmark);

                try
                {
                    ShapeRange  shapeRange  = otherFile.Shapes.Range(1);
                    InlineShape inlineShape = shapeRange.ConvertToInlineShape();
                    inlineShape.Select();
                    _wordApp.Selection.Copy();
                }
                catch (Exception)
                {
                    Shape shape       = otherFile.Shapes[1];
                    Frame inlineShape = shape.ConvertToFrame();
                    inlineShape.Select();
                    _wordApp.Selection.Copy();
                }
                finally
                {
                    bookmarkPic.Paste();
                    if (isCloseTheFile)
                    {
                        CloseWord(otherFile, otherFilePath);
                    }
                }
            }
            catch (Exception ex)
            {
                _needWrite = false;
                Dispose();
                throw new Exception(string.Format("错误信息:{0}.{1}", ex.StackTrace.ToString(), ex.Message));
            }

            return("创建成功");
        }