Image 将文本包装在图像顶部的C代码-OpenXml

Image 将文本包装在图像顶部的C代码-OpenXml,image,text,header,openxml,document,Image,Text,Header,Openxml,Document,我正在使用OpenXml创建word文档。文档由包含图像的标题部分组成。 现在我必须在图像顶部显示一个动态文本。文本将位于横幅图像的正中心,图像应看起来像背景 这将只适用于锚标记,所以,替换内联代码,请找到下面的代码,它适合我 Drawing drawing = new Drawing(); DW.Anchor anchor2 = new DW.Anchor() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom =

我正在使用OpenXml创建word文档。文档由包含图像的标题部分组成。 现在我必须在图像顶部显示一个动态文本。文本将位于横幅图像的正中心,图像应看起来像背景


这将只适用于锚标记,所以,替换内联代码,请找到下面的代码,它适合我

    Drawing drawing = new Drawing();
    DW.Anchor anchor2 = new DW.Anchor() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)114300U, DistanceFromRight = (UInt32Value)114300U, SimplePos = false, RelativeHeight = (UInt32Value)251662848U, BehindDoc = true, Locked = false, LayoutInCell = true, AllowOverlap = true };
    DW.SimplePosition simplePosition2 = new DW.SimplePosition() { X = 0L, Y = 0L };
    DW.HorizontalPosition horizontalPosition2 = new DW.HorizontalPosition() { RelativeFrom = DW.HorizontalRelativePositionValues.Column };
    DW.PositionOffset positionOffset3 = new DW.PositionOffset();
    positionOffset3.Text = "0";
    horizontalPosition2.Append(positionOffset3);
    DW.VerticalPosition verticalPosition2 = new DW.VerticalPosition() { RelativeFrom = DW.VerticalRelativePositionValues.Paragraph };
    DW.PositionOffset positionOffset4 = new DW.PositionOffset();
    positionOffset4.Text = "32385";
    verticalPosition2.Append(positionOffset4);
    DW.Extent extent = new DW.Extent() { Cx = 5950000L, Cy = 745000L };
    DW.EffectExtent effetctEx = new DW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L, };
    DW.WrapTight wrapTight1 = new DW.WrapTight() { WrapText = DW.WrapTextValues.BothSides };
    DW.WrapPolygon wrapPolygon1 = new DW.WrapPolygon() { Edited = false };
    DW.StartPoint startPoint1 = new DW.StartPoint() { X = 0L, Y = 0L };
    DW.LineTo lineTo1 = new DW.LineTo() { X = 0L, Y = 21036L };
    DW.LineTo lineTo2 = new DW.LineTo() { X = 21551L, Y = 21036L };
    DW.LineTo lineTo3 = new DW.LineTo() { X = 21551L, Y = 0L };
    DW.LineTo lineTo4 = new DW.LineTo() { X = 0L, Y = 0L };
    wrapPolygon1.Append(startPoint1);
    wrapPolygon1.Append(lineTo1);
    wrapPolygon1.Append(lineTo2);
    wrapPolygon1.Append(lineTo3);
    wrapPolygon1.Append(lineTo4);
    wrapTight1.Append(wrapPolygon1);
    DW.DocProperties docProperties = new DW.DocProperties() { Id = (UInt32Value)1U, Name = "Header Logo" };
    DW.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties = new DW.NonVisualGraphicFrameDrawingProperties();
    A.GraphicFrameLocks graphicFrameLocks = new A.GraphicFrameLocks() { NoChangeAspect = true };
    A.Graphic graphic = new A.Graphic() ;
    A.GraphicData graphicData = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };
    PIC.Picture picture = new PIC.Picture() ; 
    PIC.NonVisualPictureProperties nonVisualPictureProperties = new PIC.NonVisualPictureProperties() ;
    PIC.NonVisualDrawingProperties nonVisualDrawingProperties = new PIC.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = "HeadeLogo.jpeg" };
    PIC.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties = new PIC.NonVisualPictureDrawingProperties() ;
    PIC.BlipFill blipFill = new PIC.BlipFill();
    A.Blip blip = new A.Blip() { Embed = imageLogoHeader, CompressionState = A.BlipCompressionValues.Print };
    A.Stretch stretch = new A.Stretch();
    A.FillRectangle fillRectangle = new A.FillRectangle();
    PIC.ShapeProperties shapeProperties = new PIC.ShapeProperties( 
   new A.Transform2D(new A.Offset() { X = 0L, Y = 0L }, new A.Extents() { Cx = 5950000L, Cy = 745000L }),
   new A.PresetGeometry(new A.AdjustValueList()) { Preset = A.ShapeTypeValues.Rectangle });
    nonVisualPictureProperties.Append(nonVisualDrawingProperties);
    nonVisualPictureProperties.Append(nonVisualPictureDrawingProperties);
    picture.Append(nonVisualPictureProperties);
    blipFill.Append(blip);       
    stretch.Append(fillRectangle);
    blipFill.Append(stretch);
    picture.Append(blipFill);
    picture.Append(shapeProperties);
    graphicData.Append(picture);
    graphic.Append(graphicData);
    anchor2.Append(simplePosition2);
    anchor2.Append(horizontalPosition2);
    anchor2.Append(verticalPosition2);
    anchor2.Append(extent);
    anchor2.Append(effetctEx);
    anchor2.Append(wrapTight1);
    anchor2.Append(docProperties);
    anchor2.Append(nonVisualGraphicFrameDrawingProperties);
    anchor2.Append(graphic);
    drawing.Append(anchor2);

    var header = new Header();
    var paragraph = new Paragraph();
    var run = new Run();
    run.Append(drawing);

    Paragraph paragraph2 = new Paragraph() ;
    Run run1 = new Run();
    Picture picture1 = new Picture();

     V.Shape shape1 = new V.Shape() { Id = "WordPictureWatermark75517470", Style = "position:absolute;mso-wrap-style:Tight", AllowInCell = false, Filled = false, Stroked = false, Type = "TextWrappingValues.Tight"} ;

    picture1.Append(shape1);
    run1.Append(picture1);
    paragraph2.Append(run1);
    header.Append(paragraph2);

    header.Append(
    new Paragraph(
              new ParagraphProperties(                  
                    new ParagraphBorders(
                    new TopBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new LeftBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new BottomBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new RightBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace })), 
        new Run(run)
        ),
     new Paragraph(
        new ParagraphProperties(
            new ParagraphBorders(
                new TopBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new LeftBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new BottomBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new RightBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace }),
            new Justification() { Val = txtAlign },
            new ParagraphMarkRunProperties(
                new RunFonts() { Ascii = fntType, HighAnsi = fntType, ComplexScript = fntType },
                new Bold(),
                new FontSize() { Val = fntSize },
                new FontSizeComplexScript() { Val = fntSize })),
        new Run(
            new RunProperties(
                new RunFonts() { Ascii = fntType, HighAnsi = fntType, ComplexScript = fntType },
                new Bold(),
                new FontSize() { Val = fntSize },
                new FontSizeComplexScript() { Val = fntSize }),
             new Text(bText)
        )

您具体想要什么,请也发布您的试用版?
    Drawing drawing = new Drawing();
    DW.Anchor anchor2 = new DW.Anchor() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)114300U, DistanceFromRight = (UInt32Value)114300U, SimplePos = false, RelativeHeight = (UInt32Value)251662848U, BehindDoc = true, Locked = false, LayoutInCell = true, AllowOverlap = true };
    DW.SimplePosition simplePosition2 = new DW.SimplePosition() { X = 0L, Y = 0L };
    DW.HorizontalPosition horizontalPosition2 = new DW.HorizontalPosition() { RelativeFrom = DW.HorizontalRelativePositionValues.Column };
    DW.PositionOffset positionOffset3 = new DW.PositionOffset();
    positionOffset3.Text = "0";
    horizontalPosition2.Append(positionOffset3);
    DW.VerticalPosition verticalPosition2 = new DW.VerticalPosition() { RelativeFrom = DW.VerticalRelativePositionValues.Paragraph };
    DW.PositionOffset positionOffset4 = new DW.PositionOffset();
    positionOffset4.Text = "32385";
    verticalPosition2.Append(positionOffset4);
    DW.Extent extent = new DW.Extent() { Cx = 5950000L, Cy = 745000L };
    DW.EffectExtent effetctEx = new DW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L, };
    DW.WrapTight wrapTight1 = new DW.WrapTight() { WrapText = DW.WrapTextValues.BothSides };
    DW.WrapPolygon wrapPolygon1 = new DW.WrapPolygon() { Edited = false };
    DW.StartPoint startPoint1 = new DW.StartPoint() { X = 0L, Y = 0L };
    DW.LineTo lineTo1 = new DW.LineTo() { X = 0L, Y = 21036L };
    DW.LineTo lineTo2 = new DW.LineTo() { X = 21551L, Y = 21036L };
    DW.LineTo lineTo3 = new DW.LineTo() { X = 21551L, Y = 0L };
    DW.LineTo lineTo4 = new DW.LineTo() { X = 0L, Y = 0L };
    wrapPolygon1.Append(startPoint1);
    wrapPolygon1.Append(lineTo1);
    wrapPolygon1.Append(lineTo2);
    wrapPolygon1.Append(lineTo3);
    wrapPolygon1.Append(lineTo4);
    wrapTight1.Append(wrapPolygon1);
    DW.DocProperties docProperties = new DW.DocProperties() { Id = (UInt32Value)1U, Name = "Header Logo" };
    DW.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties = new DW.NonVisualGraphicFrameDrawingProperties();
    A.GraphicFrameLocks graphicFrameLocks = new A.GraphicFrameLocks() { NoChangeAspect = true };
    A.Graphic graphic = new A.Graphic() ;
    A.GraphicData graphicData = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };
    PIC.Picture picture = new PIC.Picture() ; 
    PIC.NonVisualPictureProperties nonVisualPictureProperties = new PIC.NonVisualPictureProperties() ;
    PIC.NonVisualDrawingProperties nonVisualDrawingProperties = new PIC.NonVisualDrawingProperties() { Id = (UInt32Value)0U, Name = "HeadeLogo.jpeg" };
    PIC.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties = new PIC.NonVisualPictureDrawingProperties() ;
    PIC.BlipFill blipFill = new PIC.BlipFill();
    A.Blip blip = new A.Blip() { Embed = imageLogoHeader, CompressionState = A.BlipCompressionValues.Print };
    A.Stretch stretch = new A.Stretch();
    A.FillRectangle fillRectangle = new A.FillRectangle();
    PIC.ShapeProperties shapeProperties = new PIC.ShapeProperties( 
   new A.Transform2D(new A.Offset() { X = 0L, Y = 0L }, new A.Extents() { Cx = 5950000L, Cy = 745000L }),
   new A.PresetGeometry(new A.AdjustValueList()) { Preset = A.ShapeTypeValues.Rectangle });
    nonVisualPictureProperties.Append(nonVisualDrawingProperties);
    nonVisualPictureProperties.Append(nonVisualPictureDrawingProperties);
    picture.Append(nonVisualPictureProperties);
    blipFill.Append(blip);       
    stretch.Append(fillRectangle);
    blipFill.Append(stretch);
    picture.Append(blipFill);
    picture.Append(shapeProperties);
    graphicData.Append(picture);
    graphic.Append(graphicData);
    anchor2.Append(simplePosition2);
    anchor2.Append(horizontalPosition2);
    anchor2.Append(verticalPosition2);
    anchor2.Append(extent);
    anchor2.Append(effetctEx);
    anchor2.Append(wrapTight1);
    anchor2.Append(docProperties);
    anchor2.Append(nonVisualGraphicFrameDrawingProperties);
    anchor2.Append(graphic);
    drawing.Append(anchor2);

    var header = new Header();
    var paragraph = new Paragraph();
    var run = new Run();
    run.Append(drawing);

    Paragraph paragraph2 = new Paragraph() ;
    Run run1 = new Run();
    Picture picture1 = new Picture();

     V.Shape shape1 = new V.Shape() { Id = "WordPictureWatermark75517470", Style = "position:absolute;mso-wrap-style:Tight", AllowInCell = false, Filled = false, Stroked = false, Type = "TextWrappingValues.Tight"} ;

    picture1.Append(shape1);
    run1.Append(picture1);
    paragraph2.Append(run1);
    header.Append(paragraph2);

    header.Append(
    new Paragraph(
              new ParagraphProperties(                  
                    new ParagraphBorders(
                    new TopBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new LeftBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new BottomBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                    new RightBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace })), 
        new Run(run)
        ),
     new Paragraph(
        new ParagraphProperties(
            new ParagraphBorders(
                new TopBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new LeftBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new BottomBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace },
                new RightBorder() { Val = bdrCount, Color = bdrColor, Size = bdrSize, Space = bdrSpace }),
            new Justification() { Val = txtAlign },
            new ParagraphMarkRunProperties(
                new RunFonts() { Ascii = fntType, HighAnsi = fntType, ComplexScript = fntType },
                new Bold(),
                new FontSize() { Val = fntSize },
                new FontSizeComplexScript() { Val = fntSize })),
        new Run(
            new RunProperties(
                new RunFonts() { Ascii = fntType, HighAnsi = fntType, ComplexScript = fntType },
                new Bold(),
                new FontSize() { Val = fntSize },
                new FontSizeComplexScript() { Val = fntSize }),
             new Text(bText)
        )