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";
     }
 }
Example #2
0
        //批量模式按钮 VVV
        private void btn_nxtTeX_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Word.Document ThisDoc = Globals.ThisAddIn.Application.ActiveDocument;
            Microsoft.Office.Interop.Word.Range    TexItem = null;
            ThisDoc.Application.Selection.SetRange(ThisDoc.Application.Selection.Start, ThisDoc.Application.Selection.End + 1);
            TexItem = ThisDoc.Application.Selection.GoToNext(WdGoToItem.wdGoToGraphic);
            TexItem.SetRange(TexItem.Start, TexItem.End + 1);
            TexItem.Select();
            InlineShapes SelectedObj      = ThisDoc.Application.Selection.InlineShapes;
            InlineShape  SelectedObjFirst = SelectedObj[1];

            if (ThisDoc == null || ThisDoc.ReadOnly)
            {
                return;
            }
            if (SelectedObj.Count == 0)
            {
                return;
            }
            if (!SelectedObjFirst.AlternativeText.Contains("WordxTex_TexContent"))
            {
                return;
            }
            texCodeBox.Clear();
            texCodeBox.Text = SelectedObjFirst.AlternativeText;
        }
Example #3
0
        private void _insertImg(string filePath)
        {
            object unite = WdUnits.wdStory;
            //定义要向文档中插入图片的位置
            Range range = wordDoc.Paragraphs.Last.Range;
            //定义该图片是否为外部链接
            object linkToFile = false;//默认
            //定义插入的图片是否随word一起保存
            object saveWithDocument = true;
            object rangeTemp        = range;
            //向word中写入图片
            InlineShape inlineShape = wordDoc.InlineShapes.AddPicture(filePath, ref linkToFile,
                                                                      ref saveWithDocument, ref rangeTemp);
            float maxHeight = 575;

            if (inlineShape.Height > inlineShape.Width)
            {
                float ratio = inlineShape.Height / inlineShape.Width;
                inlineShape.Height = maxHeight;
                inlineShape.Width  = inlineShape.Height / ratio;
            }
            object oStyleName = MSWord.WdBuiltinStyle.wdStyleBodyText;

            range.set_Style(ref oStyleName);
            Object Nothing = Missing.Value;

            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //居中显示图片
            wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
        }
Example #4
0
        /// <summary>
        /// Chen pic vao WordDoc voi kich thuoc xac dinh
        /// </summary>
        /// <param name="imagePath">Duong dan cua pic tren o dia</param>
        /// <param name="imageH">Chieu cao pic, don vi la inches</param>
        /// <param name="imageW">Chieu rong pic, don vi la inches</param>
        public static void AddPicture(string bookmarkName, string imagePath, float imageH, float imageW)
        {
            // Declaration of the variables

            Object myFalse  = false;
            Object myTrue   = true;
            Object endOfDoc = "\\endofdoc";
            Object oPic     = bookmarkName;

            if (!_doc.Bookmarks.Exists(bookmarkName))
            {
                throw new Exception("Bookmark cho pic khong ton tai trong WordDoc");
            }

            // Set the position where the image will be placed

            Object myImageRange = _doc.Bookmarks.Item(ref oPic).Range;

            Range myRange = _doc.Bookmarks.Item(ref endOfDoc).Range;

            // Add the picture to the document

            InlineShape docPic = myRange.InlineShapes.AddPicture(imagePath, ref myFalse, ref myTrue, ref myImageRange);

            // chuyen sang don vi inches
            docPic.Height = _msWord.InchesToPoints(imageH);
            docPic.Width  = _msWord.InchesToPoints(imageW);
        }
        public void InsertPictureSignatureByBookMark(object bookMark, string replacePic)
        {
            try
            {
                object linkToFile       = false;
                object saveWithDocument = true;
                object Nothing          = System.Reflection.Missing.Value;
                if (doc.Bookmarks.Exists(Convert.ToString(bookMark)) == true)
                {
                    //查找书签
                    doc.Bookmarks.get_Item(ref bookMark).Select();
                    //设置图片位置
                    app.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
                    //在书签的位置添加图片
                    InlineShape insh = app.Selection.InlineShapes.AddPicture(replacePic, ref linkToFile, ref saveWithDocument, ref Nothing);

                    insh.Height = 40;
                    insh.Width  = 57;
                }
                else
                {
                    Writelog(string.Format("there  is  no the bookmark named {0}", bookMark));
                }
            }
            catch (Exception ex)
            {
                Writelog(string.Format("InsertPictureSignatureByBookMark error:{0}", ex.Message));
            }
        }
        private void AddImageToDocument(Microsoft.Office.Interop.Word.Document doc)
        {
            object oEndOfDoc  = "SIGNATURE";
            Range  imageRange = doc.Bookmarks.get_Item(ref oEndOfDoc).Range;

            string imagePath = @"C:\AdarshData\Project Documents\OrthoInitialImplementation\JsonToDocumentPOC\JsonToDocumentPOC\Data\Signature.jpg";

            // Create an InlineShape in the InlineShapes collection where the picture should be added later
            // It is used to get automatically scaled sizes.
            InlineShape autoScaledInlineShape = imageRange.InlineShapes.AddPicture(imagePath);
            float       scaledWidth           = autoScaledInlineShape.Width;
            float       scaledHeight          = autoScaledInlineShape.Height;

            autoScaledInlineShape.Delete();

            // Create a new Shape and fill it with the picture
            Shape newShape = doc.Shapes.AddShape(1, 0, 0, scaledWidth, scaledHeight);

            newShape.Fill.UserPicture(imagePath);

            // Convert the Shape to an InlineShape and optional disable Border
            InlineShape finalInlineShape = newShape.ConvertToInlineShape();

            finalInlineShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;

            // Cut the range of the InlineShape to clipboard
            finalInlineShape.Range.Cut();

            // And paste it to the target Range
            imageRange.Paste();
        }
Example #7
0
        public Document CreateBookmarkedDocument(FileInfo template, Hashtable hbookmarks)
        {
            Document document = wordApp.Documents.Add(template.FullName);

            try
            {
                foreach (var bookmark in hbookmarks.Keys)
                {
                    if (document.Bookmarks.Exists(bookmark.ToString()))
                    {
                        var ts = new TypeSwitch()
                                 .Case((InsertedObject insertedObject) =>
                        {
                            InlineShape shape     = document.Bookmarks[bookmark].Range.InlineShapes.AddPicture(FileName: insertedObject.FromFile.FullName);
                            var proportion        = shape.Width / shape.Height;
                            shape.LockAspectRatio = MsoTriState.msoTrue;
                            shape.Height          = insertedObject.Height;
                            shape.Width           = shape.Height * proportion;
                        })
                                 .Case((string insertedstr) => document.Bookmarks[bookmark].Range.Text = insertedstr)
                                 .Case((CreateFunc createFunc) => { createFunc.Invoke(document.Bookmarks[bookmark].Range); });
                        ts.Switch(hbookmarks[bookmark]);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.Error(ex.Message);
            }
            return(document);
        }
        // Function to insert a photo at a specific location (range) within a word document
        public static void insertImage(Document doc, Range rng, String path)
        {
            // Create an InlineShape in the InlineShapes collection where the picture should be added later
            // It is used to get automatically scaled sizes.
            InlineShape autoScaledInlineShape = rng.InlineShapes.AddPicture(path);
            float       scaledWidth           = autoScaledInlineShape.Width;
            float       scaledHeight          = autoScaledInlineShape.Height;

            autoScaledInlineShape.Delete();

            // Create a new Shape and fill it with the picture
            Shape newShape = doc.Shapes.AddShape(1, 0, 0, scaledWidth, scaledHeight);

            newShape.Fill.UserPicture(path);

            // Convert the Shape to an InlineShape and optional disable Border
            InlineShape finalInlineShape = newShape.ConvertToInlineShape();

            finalInlineShape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;

            // Cut the range of the InlineShape to clipboard
            finalInlineShape.Range.Cut();

            // And paste it to the target Range
            rng.Paste();
        }
Example #9
0
 /// <summary>
 /// 使用指定的文档和形状初始化段落
 /// </summary>
 /// <param name="doc">这个段落所在的文档</param>
 /// <param name="PackShape">这个段落所封装的形状对象</param>
 /// <param name="Content">Word对象所封装的图表</param>
 public WordParagraphChart(WordDocument doc, InlineShape PackShape, TChart Content)
     : base(doc, PackShape)
 {
     if (PackShape.HasChart != Microsoft.Office.Core.MsoTriState.msoTrue)
     {
         throw new Exception("此形状没有包含图表");
     }
     this.Content = Content;
 }
Example #10
0
        /// <summary>
        /// Fetch an evidence from the temp folder referenced by the evidence ID (step number) and write it to the target document.
        /// </summary>
        /// <param name="strEvidenceID"></param>
        private static void writeEvidence(string strEvidenceID)
        {
            string      strScreenshotImageURI;
            Range       rngScreenshotRange = null;
            InlineShape shpScreenshot      = null;

            int iEvidenceOrdinal = tpPlan.lstStrPropEvidenceID.IndexOf(strEvidenceID);
            int iTableID         = iEvidenceOrdinal + 2;


            strScreenshotImageURI = evEvidence.dictPropActualEvidences[strEvidenceID].strPropEvidenceImageURI;

            foreach (InlineShape shpImage in docTargetDocument.InlineShapes)
            {
                if (strEvidenceID.Equals(shpImage.AlternativeText))
                {
                    shpScreenshot      = shpImage;
                    rngScreenshotRange = shpImage.Range;
                    break;
                }
            }

            if (shpScreenshot == null || rngScreenshotRange == null)
            {
                Log("Corrupted target document. Could not save evidence for " + strEvidenceID);
                return;
            }


            try
            {
                shpScreenshot.Delete();
                dictShpScreenshots[strEvidenceID] = rngScreenshotRange.InlineShapes.AddPicture(strScreenshotImageURI);
                dictShpScreenshots[strEvidenceID].AlternativeText = strEvidenceID;
                dictShpScreenshots[strEvidenceID].Title           = strEvidenceID;
                Log(" \nAdd actual " + dictShpScreenshots[strEvidenceID].AlternativeText);
                if (!lstStrEvidencesWritten.Contains(strEvidenceID))
                {
                    lstStrEvidencesWritten.Add(strEvidenceID);
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception)
            {
                MessageBox.Show(new Form {
                    TopMost = true
                }, "Could not save evidence for " + strEvidenceID);
            }

            deleteEvidenceImage(strScreenshotImageURI);
            docTargetDocument.Tables[iTableID].Rows[1].Cells[4].Range.Text = evEvidence.dictPropActualEvidences[strEvidenceID].strStatus;
            docTargetDocument.Tables[iTableID].Rows[2].Cells[2].Range.Text = evEvidence.dictPropActualEvidences[strEvidenceID].strComments;
            saveTargetDocument();
        }
        private void CreateImage(Document document)
        {
            //string imagePath = Server.MapPath("logo/venish.jpg");
            string imagePath = "D:\\Promact Infotech\\KPMG\\Demo Application\\ReportDownloadApplication\\ReportDownloadApplication\\logo\\venish.jpg";

            oImage        = document.InlineShapes.AddPicture(imagePath, ref missing, ref missing, ref missing);
            oImage.Width  = WordApp.InchesToPoints(6.25f);
            oImage.Height = WordApp.InchesToPoints(3.57f);
        }
    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();
        /*...*/
    }
Example #13
0
        private void btn_batchEdit_Click(object sender, RibbonControlEventArgs e)
        {
            Microsoft.Office.Interop.Word.Document ThisDoc = Globals.ThisAddIn.Application.ActiveDocument;
            if (ThisDoc == null || ThisDoc.ReadOnly)
            {
                return;
            }
            int IntlStart = ThisDoc.Application.Selection.Start;
            int IntlEnd   = ThisDoc.Application.Selection.End;

            ThisDoc.Application.Selection.SetRange(ThisDoc.Application.Selection.Start, ThisDoc.Application.Selection.Start + 1);

            Selection TexObj       = ThisDoc.Application.Selection;
            Range     TexItem      = null;
            bool      if_TexObject = false;

            InlineShape TexObjInline          = null;
            int         TexObjInline_prvstart = 0;
            int         TexObjInline_start    = 1;

            if (TexObj.InlineShapes.Count != 0)
            {
                TexObjInline = TexObj.InlineShapes[1];
                if_TexObject = (TexObjInline.Type != WdInlineShapeType.wdInlineShapePicture);
                if_TexObject = (if_TexObject && TexObjInline.AlternativeText.Contains("WordxTex_TexContent"));
            }
            else
            {
                TexItem = ThisDoc.Application.Selection.GoToNext(WdGoToItem.wdGoToGraphic);
                ThisDoc.Application.Selection.SetRange(ThisDoc.Application.Selection.Start, ThisDoc.Application.Selection.Start + 1);
                TexObj = ThisDoc.Application.Selection;
            }
            while ((!if_TexObject) && TexObj.InlineShapes.Count != 0 && ((TexObjInline_prvstart != TexObjInline_start)))
            {
                TexObjInline_prvstart = TexObjInline_start;
                TexItem = ThisDoc.Application.Selection.GoToNext(WdGoToItem.wdGoToGraphic);
                ThisDoc.Application.Selection.SetRange(ThisDoc.Application.Selection.Start, ThisDoc.Application.Selection.Start + 1);
                TexObj             = ThisDoc.Application.Selection;
                TexObjInline_start = TexObj.Start;
                TexObjInline       = TexObj.InlineShapes[1];
                if_TexObject       = (TexObjInline.Type != WdInlineShapeType.wdInlineShapePicture);
                if_TexObject       = (if_TexObject && TexObjInline.AlternativeText.Contains("WordxTex_TexContent"));
            }
            ;
            if (if_TexObject)
            {
                LaTexEdt CodeEditor = new LaTexEdt(true, TexObjInline.AlternativeText, 0, 0);
                //CodeEditor.updateSRC(TexObjInline.AlternativeText);
                CodeEditor.Show();
            }
            else
            {
                ThisDoc.Application.Selection.SetRange(IntlStart, IntlEnd);
            }
        }
Example #14
0
        private static void writePrerequisiteEvidence(string strPrerequisiteEvidenceImageURI)
        {
            while (!bTargetDocumentOpen || !bReadyToInsertPrerequisiteEvidences)
            {
                ;
            }

            InlineShape shpFirstPrerequisiteEvidence = null, shpLastPrerequisiteEvidence = null;
            Range       rngPrerequisiteEvidences = null;

            for (int i = 1; i <= docTargetDocument.InlineShapes.Count; i++)
            {
                if (PREREQUISITE_ALT_TEXT.Equals(docTargetDocument.InlineShapes[i].AlternativeText))
                {
                    if (null == shpFirstPrerequisiteEvidence)
                    {
                        shpFirstPrerequisiteEvidence = docTargetDocument.InlineShapes[i];
                    }
                    shpLastPrerequisiteEvidence = docTargetDocument.InlineShapes[i];
                }
                if (lstPropEvidenceID.Contains(docTargetDocument.InlineShapes[i].AlternativeText))
                {
                    break;
                }
            }



            if (null == shpFirstPrerequisiteEvidence)
            {
                docTargetDocument.Tables[1].Range.Next(WdUnits.wdSentence, 3).Delete(1); // delete pre-requisite evidence placeholder. 1 paragraph marker + 2 sentences away from the first table
                shpLastPrerequisiteEvidence = docTargetDocument.Tables[1].Range.Next(WdUnits.wdSentence, 3).InlineShapes.AddPicture(strPrerequisiteEvidenceImageURI);
            }
            else
            {
                rngPrerequisiteEvidences = shpLastPrerequisiteEvidence.Range;
                rngPrerequisiteEvidences.SetRange(rngPrerequisiteEvidences.End + 2, rngPrerequisiteEvidences.End + 2);
                shpLastPrerequisiteEvidence = rngPrerequisiteEvidences.InlineShapes.AddPicture(strPrerequisiteEvidenceImageURI);
            }

            shpLastPrerequisiteEvidence.AlternativeText = PREREQUISITE_ALT_TEXT;
            shpLastPrerequisiteEvidence.Title           = PREREQUISITE_ALT_TEXT;
            rngPrerequisiteEvidences = shpLastPrerequisiteEvidence.Range;
            rngPrerequisiteEvidences.Collapse(WdCollapseDirection.wdCollapseEnd);
            rngPrerequisiteEvidences.InsertBreak(WdBreakType.wdPageBreak);

            Log("Written prerequisite evidence " + strPrerequisiteEvidenceImageURI);


            if (File.Exists(strPrerequisiteEvidenceImageURI))
            {
                File.Delete(strPrerequisiteEvidenceImageURI);
            }
        }
Example #15
0
 private void showChart(Document Doc)
 {
     for (int i = 1; i <= Doc.InlineShapes.Count; i++)
     {
         InlineShape s = Doc.InlineShapes[i];
         if (s.HasChart == MsoTriState.msoTrue && s.LinkFormat != null)
         {
             string linkSource = s.LinkFormat.SourceFullName;
             MessageBox.Show(linkSource);
         }
     }
 }
Example #16
0
        /// <summary>
        /// Write an image to the end of the active document
        /// </summary>
        /// <param name="filePath"></param>
        public WordController WriteImage(FilePath filePath)
        {
            W.Document  doc    = ActiveDocument;
            Range       range  = EndRange();
            InlineShape iShape = doc.InlineShapes.AddPicture(filePath.Path, false, true, range);

            W.Shape shape = iShape.ConvertToShape();
            shape.Left            = (float)WdShapePosition.wdShapeCenter;
            shape.WrapFormat.Type = WdWrapType.wdWrapInline;
            iShape.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            return(this);
        }
        /// <summary>
        /// 插入图片
        /// </summary>
        /// <param name="range">图片位置</param>
        /// <param name="picPath">图片文件位置</param>
        /// <param name="width">图片宽度</param>
        /// <param name="height">图片高度</param>
        public InlineShape InsertPicture(Range range, string picPath, float width, float height)
        {
            object      link     = false;
            object      savewith = true;
            object      rng      = range;
            InlineShape inline   = this.WordDoc.InlineShapes.AddPicture(Path.GetFullPath(picPath), ref link, ref savewith,
                                                                        ref rng);

            inline.Width  = width;
            inline.Height = height;
            return(inline);
        }
Example #18
0
        /// <summary> 在文档正文中插入一张图片</summary>
        /// <param name="picPath">图片的文件路径</param>
        /// <param name="width">图片的宽度,单位为 point </param>>
        /// <param name="height">图片的高度,单位为 point </param>>
        /// <returns></returns>
        public InlineShape InsertPicture(int position, string picPath,
                                         float width, float height, WordStyle style = WordStyle.Picture)
        {
            var rg = Document.Range(position, position);

            InlineShape shape = rg.InlineShapes.AddPicture(picPath);

            shape.Width  = width;
            shape.Height = height;
            WordStyles.SetStyle(shape.Range, style);
            return(shape);
        }
Example #19
0
        void ThisDocument_BeforeDoubleClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
        {
            Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);

            int numShapes = Application.Selection.InlineShapes.Count;

            if (numShapes > 0)
            {
                InlineShape s = Application.Selection.InlineShapes[1];
                sendViewpointMessage(s.AlternativeText);
            }
        }
Example #20
0
        /// <summary>
        /// 当前word插入图片
        /// </summary>
        /// <returns></returns>
        protected InlineShape AddPicture(string picFileName, Document doc, Range range, float width = 0, float height = 0)
        {
            range.Select();
            InlineShape image = doc.InlineShapes.AddPicture(picFileName, ref _missing, ref _missing, range);

            if (width != 0 && height != 0)
            {
                image.Width  = width;
                image.Height = height;
            }
            return(image);
        }
Example #21
0
        //插入图片
        public void InsertPicture(string bookmark, string picturePath, float width, float hight)
        {
            object      miss             = System.Reflection.Missing.Value;
            object      oStart           = bookmark;
            object      linkToFile       = false;                                        //图片是否为外部链接
            object      saveWithDocument = true;                                         //图片是否随文档一起保存
            object      range            = wordDoc.Bookmarks.get_Item(ref oStart).Range; //图片插入位置
            InlineShape p = wordDoc.InlineShapes.AddPicture(picturePath, ref linkToFile, ref saveWithDocument, ref range);

            p.Width  = width;
            p.Height = hight;
//             wordDoc.Application.ActiveDocument.InlineShapes[1].Width = width; //设置图片宽度
//             wordDoc.Application.ActiveDocument.InlineShapes[1].Height = hight; //设置图片高度
        }
Example #22
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);
            }
        }
Example #23
0
        public void InsertPictureStatic(string picPath, int width, int height)
        {
            object      missing          = System.Reflection.Missing.Value;
            object      LinkToFile       = false;
            object      SaveWithDocument = true;
            object      Anchor           = oWordApplic.Selection.Range;
            InlineShape inlineShape      = oWordApplic.ActiveDocument.InlineShapes.AddPicture(picPath, ref LinkToFile, ref SaveWithDocument, ref Anchor);

            inlineShape.Width  = width;  // 图片宽度
            inlineShape.Height = height; // 图片高度
            Shape cShape = inlineShape.ConvertToShape();

            cShape.WrapFormat.Type = WdWrapType.wdWrapFront;
            //oWordApplic.Selection.InlineShapes.AddPicture(picPath, ref missing, ref missing, ref missing);
        }
Example #24
0
        public static void ImagesFixup(Document activeDoc, float brightness, float contrast, float maxWidth, float maxHeight, ref UtilityStatus status)
        {
            status.imageCount = activeDoc.InlineShapes.Count;

            status.currentImage = 0;
            while (status.currentImage < status.imageCount)
            {
                ++status.currentImage;
                InlineShape curShape = activeDoc.InlineShapes[status.currentImage];

                if (curShape.Type == WdInlineShapeType.wdInlineShapePicture)
                {                                  // If it's a picture we can do fixup with it
                    if (curShape.Width > maxWidth) // Too Big, must horizontally
                    {
                        float scaling = maxWidth / curShape.Width;
                        curShape.Width  = maxWidth;
                        curShape.Height = curShape.Height * scaling;
                        //curShape.ScaleWidth = scaling;
                        //curShape.ScaleHeight = scaling;
                    }

                    if (curShape.Height > maxHeight)
                    {
                        float scaling = maxHeight / curShape.Height;
                        curShape.Height = maxHeight;
                        curShape.Width  = curShape.Width * scaling;
                        //curShape.ScaleWidth = scaling;
                        //curShape.ScaleHeight = scaling;
                    }


                    if (curShape.Height > 20)
                    {
                        // Adjust/Set Brightness/Contrast
                        curShape.PictureFormat.Brightness = .5F + (brightness / 200F);
                        curShape.PictureFormat.Contrast   = .5F + (contrast / 200F);

                        // Clear Indent/Set Centered
                        curShape.Range.ParagraphFormat.LeftIndent  = 0;
                        curShape.Range.ParagraphFormat.RightIndent = 0;
                        curShape.Range.ParagraphFormat.Alignment   = WdParagraphAlignment.wdAlignParagraphCenter;
                    }
                }
                System.Threading.Thread.Yield();
            }
        }
Example #25
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();
            }           
        }
Example #26
0
 public void InsertPictureSignatureByRange(Range range, string pictureFullPath)
 {
     try
     {
         object      Anchor           = range;
         object      LinkToFile       = false;
         object      SaveWithDocument = true;
         InlineShape insh             = doc.InlineShapes.AddPicture(pictureFullPath, ref LinkToFile, ref SaveWithDocument,
                                                                    ref Anchor);
         insh.Height = 40;
         insh.Width  = 57;
     }
     catch (Exception ex)
     {
         Writelog(string.Format("InsertPictureSignatureByRange {0} error:{1}", pictureFullPath, ex.Message));
     }
 }
Example #27
0
        public void InsertPicture(string fileName)
        {
            var         inlineShapes = _range.InlineShapes;
            InlineShape shape        = (InlineShape)inlineShapes.GetType()
                                       .InvokeMember("AddPicture", BindingFlags.InvokeMethod, null, inlineShapes,
                                                     new object[] { fileName });

            shape.LockAspectRatio = MsoTriState.msoCTrue;
            shape.Width           = 140;
            var s = shape.ConvertToShape();

            s.WrapFormat.Type         = WdWrapType.wdWrapSquare;
            s.WrapFormat.DistanceLeft = 0;
            s.WrapFormat.DistanceTop  = 0;
            s.Left = 0;
            s.Top  = 0;
        }
Example #28
0
        /// <summary>
        /// word文档中插入excel
        /// </summary>
        /// <param name="excelFileFullName">excel文件</param>
        /// <param name="bookmark">书签名称 excel插入位置书签名称 默认为"" 插入文档末尾</param>
        /// <param name="excelWidth">excel宽</param>
        /// <param name="excelHeight">excel高</param>
        /// <returns>创建结果或错误信息</returns>
        public string InsertExcel(string excelFileFullName, string bookmark, int excelWidth = 450, int excelHeight = 200)
        {
            if (excelFileFullName.Equals(""))
            {
                throw new Exception("excel文件不能为空");
            }
            try
            {
                _currentWord.Select();

                object bk         = bookmark;
                Range  excelRange = null;

                if (_currentWord.Bookmarks.Exists(bookmark))
                {
                    excelRange = GetBookmarkRank(_currentWord, bookmark);
                }
                else
                {
                    InsertBreakPage(false);
                }

                object fileType   = @"Excel.Sheet.12"; //插入的excel 格式,HKEY_CLASSES_ROOT,所以是.12  Excel.Chart.8也可以
                object filename   = excelFileFullName; //插入的excel的位置
                object linkToFile = true;
                object rangeOLE   = excelRange;
                //添加一个OLEObject对象
                InlineShape sp = _wordApp.Selection.InlineShapes.AddOLEObject(ref fileType,
                                                                              ref filename,
                                                                              ref _missing, //真 若要将 OLE 对象链接到创建它的文件
                                                                              ref _missing, //真 图标
                                                                              ref _missing, //图标链接
                                                                              ref _missing,
                                                                              ref _missing,
                                                                              ref rangeOLE); //位置
                sp.Height = excelHeight;                                                     //200
                sp.Width  = excelWidth;
            }
            catch (Exception ex)
            {
                _needWrite = false;
                Dispose();
                throw new Exception(string.Format("错误信息:{0}.{1}", ex.StackTrace.ToString(), ex.Message));
            }
            return("创建成功");
        }
        private void btnImageFixup_Click(object sender, RibbonControlEventArgs e)
        {
            Document activeDoc = Globals.BookPublishingStartup.Application.ActiveDocument;

            float maxWidth  = activeDoc.PageSetup.PageWidth - activeDoc.PageSetup.LeftMargin - activeDoc.PageSetup.RightMargin - activeDoc.PageSetup.Gutter;
            float maxHeight = activeDoc.PageSetup.PageHeight - activeDoc.PageSetup.TopMargin - activeDoc.PageSetup.BottomMargin;

            int imageCount   = activeDoc.InlineShapes.Count;
            int currentImage = 0;

            while (currentImage < imageCount)
            {
                ++currentImage;
                InlineShape curShape = activeDoc.InlineShapes[currentImage];

                if (curShape.Type == WdInlineShapeType.wdInlineShapePicture)
                {                                  // If it's a picture we can do fixup with it
                    if (curShape.Width > maxWidth) // Too Big, must horizontally
                    {
                        float scaling = maxWidth / curShape.Width;
                        curShape.Width  = maxWidth;
                        curShape.Height = curShape.Height * scaling;
                        //curShape.ScaleWidth = scaling;
                        //curShape.ScaleHeight = scaling;
                    }

                    if (curShape.Height > maxHeight)
                    {
                        float scaling = maxHeight / curShape.Height;
                        curShape.Height = maxHeight;
                        curShape.Width  = curShape.Width * scaling;
                        //curShape.ScaleWidth = scaling;
                        //curShape.ScaleHeight = scaling;
                    }

                    // Clear any/all indents
                    if (curShape.Height > 20)
                    {
                        curShape.Range.ParagraphFormat.LeftIndent  = 0;
                        curShape.Range.ParagraphFormat.RightIndent = 0;
                        curShape.Range.ParagraphFormat.Alignment   = WdParagraphAlignment.wdAlignParagraphCenter;
                    }
                }
            }
        }
Example #30
0
        private void Application_WindowBeforeDoubleClick(Selection Sel, ref bool Cancel)
        {
            InlineShapes SelectedObj = Sel.InlineShapes;

            if (SelectedObj.Count == 0)
            {
                return;
            }
            InlineShape SelectedObjFirst = SelectedObj[1];

            if (!SelectedObjFirst.AlternativeText.Contains("WordxTex_TexContent"))
            {
                return;
            }
            LaTexEdt CodeEditor = new LaTexEdt(false, SelectedObjFirst.AlternativeText, 0, 0);

            CodeEditor.ShowDialog();
        }
 private static KeyValuePair<Range, Content> ProcessInlineShape( InlineShape _shape )
 {
     float width = _shape.Width;
      float height = _shape.Height;
      string altText = "";
      string title = "";
      try
      {
     float scaleWidth = _shape.ScaleWidth;
     if ( scaleWidth > 0.0 )
     {
        //width *= (scaleWidth / 100.0f);
     }
      }
      catch
      {
      }
      try
      {
     float scaleHeight = _shape.ScaleHeight;
     if ( scaleHeight > 0.0 )
     {
        //height *= (scaleHeight / 100.0f);
     }
      }
      catch
      {
      }
      try
      {
     altText = _shape.AlternativeText;
      }
      catch
      {
      }
      try
      {
     title = _shape.Title;
      }
      catch
      {
      }
      PngImageContent imageContent = null;
      _shape.Range.CopyAsPicture();
      object pngData = Clipboard.GetData( "PNG" );
      if ( pngData is System.IO.MemoryStream )
      {
     imageContent = new PngImageContent( (System.IO.MemoryStream) pngData, altText, title, width, height );
      }
      else
      {
     if ( Clipboard.ContainsData( DataFormats.EnhancedMetafile ) )
     {
        if ( ClipboardFunctions.OpenClipboard( IntPtr.Zero ) )
        {
           width *= 1.5f;
           height *= 1.5f;
           IntPtr data = ClipboardFunctions.GetClipboardData( DataFormats.GetFormat( DataFormats.EnhancedMetafile ).Id );
           System.Drawing.Imaging.Metafile metaFile = new System.Drawing.Imaging.Metafile( data, true );
           ClipboardFunctions.CloseClipboard();
           System.Drawing.Bitmap pngImage = new System.Drawing.Bitmap( (int) width, (int) height );
           using ( System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( pngImage ) )
           {
              g.DrawImage( metaFile, new System.Drawing.Rectangle( 0, 0, (int) width, (int) height ) );
           }
           metaFile.Dispose();
           System.IO.MemoryStream pngDataStream = new System.IO.MemoryStream();
           pngImage.Save( pngDataStream, System.Drawing.Imaging.ImageFormat.Png );
           pngDataStream.Seek( 0, System.IO.SeekOrigin.Begin );
           imageContent = new PngImageContent( pngDataStream, altText, title, width, height );
           pngImage.Dispose();
        }
     }
      }
      Clipboard.Clear();
      if ( imageContent == null )
      {
     return new KeyValuePair<Range, Content>( _shape.Range, new TextContent( String.Format( "INTERNAL ERROR: Could not convert shape to PNG image." ), Edward.ERROR_STYLE ) );
      }
      else
      {
     return new KeyValuePair<Range, Content>( _shape.Range, imageContent );
      }
 }