gpt4 book ai didi

c# - 使用open xml和C#将图像插入到word文档中

转载 作者:行者123 更新时间:2023-11-30 16:26:07 25 4
gpt4 key购买 nike

我有以下代码尝试使用打开的 xml 将图像插入到 word 文档中:

private void AddImageToBody(ImagePart imagePart)
{
// Define the reference of the image.
var element =
new Drawing(
new Inline(
new Extent() { Cx = ConvertToEmu(640), Cy = ConvertToEmu(480) },
new EffectExtent()
{
LeftEdge = 0L,
TopEdge = 0L,
RightEdge = 0L,
BottomEdge = 0L
},
new DocProperties()
{
Id = (UInt32Value)1U,
Name = "Picture 1"
},
new NonVisualGraphicFrameDrawingProperties(
new GraphicFrameLocks() { NoChangeAspect = true }
),
new Graphic(
new GraphicData(
new Picture(
new NonVisualPictureProperties(
new NonVisualDrawingProperties()
{
Id = (UInt32Value)0U,
Name = "New Bitmap Image.jpg"
},
new NonVisualPictureDrawingProperties()),
new BlipFill(
new Blip(
new BlipExtensionList(
new BlipExtension()
{
Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
}
)
)
{
Embed = mainpart.GetIdOfPart(imagePart),
CompressionState = BlipCompressionValues.Print
},
new Stretch(
new FillRectangle()
)
),
new ShapeProperties(
new Transform2D(
new Offset() { X = 0L, Y = 0L },
new Extents() { Cx = ConvertToEmu(640), Cy = ConvertToEmu(480) }
),
new PresetGeometry(
new AdjustValueList()
) { Preset = ShapeTypeValues.Rectangle }
)
)
) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }
)
)
{
DistanceFromTop = (UInt32Value)0U,
DistanceFromBottom = (UInt32Value)0U,
DistanceFromLeft = (UInt32Value)0U,
DistanceFromRight = (UInt32Value)0U
});

// Append the reference to body, the element should be in a Run.
body.AppendChild(new Paragraph(new Run(element)));
}

虽然我插入了一张图片,但插入的图片显示为空白且宽度和高度不正确。

有什么建议吗?

最佳答案

http://msdn.microsoft.com/en-us/library/bb497430.aspx 尝试 msdn“如何:将图片插入文字处理文档” .我可以使用此代码添加图像。

关于c# - 使用open xml和C#将图像插入到word文档中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com