Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#和OpenXML2.0将图像从流添加到word文档_C#_Asp.net_Openxml - Fatal编程技术网

使用c#和OpenXML2.0将图像从流添加到word文档

使用c#和OpenXML2.0将图像从流添加到word文档,c#,asp.net,openxml,C#,Asp.net,Openxml,我一直在尝试一些新的东西,我需要从流中插入图像,但每次我尝试插入图像时,它会破坏word文档,我使用的是office 2010 我有以下代码将图像添加到word文档中 private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string documentName) { var element = new Drawing(new DW.Inline(new DW.E

我一直在尝试一些新的东西,我需要从流中插入图像,但每次我尝试插入图像时,它会破坏word文档,我使用的是office 2010

我有以下代码将图像添加到word文档中

private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string documentName)
    {
        var element = new Drawing(new DW.Inline(new DW.Extent { Cx = 990000L, Cy = 792000L }, new DW.EffectExtent
        {
            LeftEdge = 0L,
            TopEdge = 0L,
            RightEdge = 0L,
            BottomEdge = 0L
        },
        new DW.DocProperties
        {
            Id = (UInt32Value)1U,
            Name = "Picture 1"
        }, new DW.NonVisualGraphicFrameDrawingProperties(new A.GraphicFrameLocks { NoChangeAspect = true }), new A.Graphic(new A.GraphicData(new PIC.Picture(new PIC.NonVisualPictureProperties(
            new PIC.NonVisualDrawingProperties
            {
                Id = (UInt32Value)0U,
                Name = documentName
            }, new PIC.NonVisualPictureDrawingProperties()), new PIC.BlipFill(new A.Blip
            {
                Embed = relationshipId,
                CompressionState =
                A.BlipCompressionValues.Print
            }, new A.Stretch(new A.FillRectangle())), new PIC.ShapeProperties(new A.Transform2D(new A.Offset { X = 0L, Y = 0L }, new A.Extents { Cx = 990000L, Cy = 792000L }), new A.PresetGeometry(
                new A.AdjustValueList()) { Preset = A.ShapeTypeValues.Rectangle })))))
                {
                    DistanceFromTop = (UInt32Value)0U,
                    DistanceFromBottom = (UInt32Value)0U,
                    DistanceFromLeft = (UInt32Value)0U,
                    DistanceFromRight = (UInt32Value)0U
                });
        wordDoc.MainDocumentPart.Document.Body.AppendChild(new Run(element));

    }

谢谢你,进退两难


但是这也没用,所以我将图像保存到一个文件夹中,并使用Interop中的AddPicture方法,为什么不使用docx库呢

3) DocX also supports 
     a) Pictures, 

像这样:
为什么不使用docx库呢

3) DocX also supports 
     a) Pictures, 

像这样:

我从来没听说过,让我试试看。我从来没听说过,让我试试看