【问题标题】:Getting Image Details For Adding To DOCX获取添加到 DOCX 的图像详细信息
【发布时间】:2012-05-25 11:21:41
【问题描述】:

我正在使用此处的 WordprocessingDocument 方法(Open XML)http://msdn.microsoft.com/en-us/library/bb497430.aspx 将图像添加到 DOCX 文件中。

我可以添加图片,但尺寸不正确。

MainDocumentPart mainPart = doc.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
      {
           imagePart.FeedData(stream);
      }


return AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), fileName);

private static Drawing AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string filename)
    { 
       long imageWidthEMU = 1900000;
       long imageHeightEMU = 350000;

       double imageWidthInInches = imageWidthEMU / 914400.0;
       double imageHeightInInches = imageHeightEMU / 914400.0;

        new DW.Extent();

        //Define the reference of the image.
        var element =
             new Drawing(
                 new DW.Inline(
                     new DW.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU },

如您所见,您手动指定尺寸(长度 + 宽度)。我无法动态获取它们。如何获得正确的图像尺寸以传递给此代码?

谢谢。

【问题讨论】:

    标签: c# c#-4.0


    【解决方案1】:

    您的问题在这里解决了: Inserting Image into DocX using OpenXML and setting the size

    没有办法通过xml文件中的指令解决。 OOXML 仅提供 <a:fill><a:tile> 选项。

    【讨论】:

      猜你喜欢
      • 2012-03-01
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多