当前位置: 首页>>代码示例>>C#>>正文


C# MainDocumentPart.GetPartById方法代码示例

本文整理汇总了C#中DocumentFormat.OpenXml.Packaging.MainDocumentPart.GetPartById方法的典型用法代码示例。如果您正苦于以下问题:C# MainDocumentPart.GetPartById方法的具体用法?C# MainDocumentPart.GetPartById怎么用?C# MainDocumentPart.GetPartById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentFormat.OpenXml.Packaging.MainDocumentPart的用法示例。


在下文中一共展示了MainDocumentPart.GetPartById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddImageParagraph

        public static Run AddImageParagraph(MainDocumentPart mainpart, string filename, string SigId)
        {
            SigId = SigId.Replace("/", "");
            byte[] imageFileBytes;
            Bitmap image = null;

            // Open a stream on the image file and read it's contents.
            using (FileStream fsImageFile = System.IO.File.OpenRead(filename))
            {
                imageFileBytes = new byte[fsImageFile.Length];
                fsImageFile.Read(imageFileBytes, 0, imageFileBytes.Length);
                image = new Bitmap(fsImageFile);
            }

            string extension = Path.GetExtension(filename);
            string ExtensionText = "image/jpeg";
            if (extension == "png")
                ExtensionText = "image/png";

            double MaxImageWidth = 0.2;
            double imgWidth = image.Width;
            double imgHeight = image.Height;
            double itmp = imgWidth / MaxImageWidth;
            double HorResolution = 1;//image.HorizontalResolution;
            double verResolution = 1;//image.VerticalResolution;

            double emuWidth = imgWidth / HorResolution / itmp;
            double emuHeight = imgHeight / verResolution / itmp;

            long imageWidthEMU = (long)((emuWidth) * 914400L);
            long imageHeightEMU = (long)((emuHeight) * 914400L);

            // add this is not already there
            try
            {
                if (mainpart.GetPartById(SigId) == null)
                {
                    var imagePart = mainpart.AddNewPart<ImagePart>(ExtensionText, SigId);

                    using (BinaryWriter writer = new BinaryWriter(imagePart.GetStream()))
                    {
                        writer.Write(imageFileBytes);
                        writer.Flush();
                    }
                }
            }
            catch // thrown if not found
            {
                var imagePart = mainpart.AddNewPart<ImagePart>(ExtensionText, SigId);

                using (BinaryWriter writer = new BinaryWriter(imagePart.GetStream()))
                {
                    writer.Write(imageFileBytes);
                    writer.Flush();
                }

            }
            WP.Run para =
            
              new WP.Run(
                new WP.Drawing(
                  new wp.Inline(

                    new wp.Extent()
                    {
                        Cx = imageWidthEMU,
                        Cy = imageHeightEMU
                    },

                    new wp.EffectExtent()
                    {
                        LeftEdge = 19050L,
                        TopEdge = 0L,
                        RightEdge = 9525L,
                        BottomEdge = 0L
                    },

                    new wp.DocProperties()
                    {
                        Id = (UInt32Value)1U,
                        Name = "Inline Text Wrapping Picture",
                        Description = GraphicDataUri
                    },

                    new wp.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 = filename
                            },
                            new pic.NonVisualPictureDrawingProperties()),

                          new pic.BlipFill(
//.........这里部分代码省略.........
开发者ID:PaoloMisson,项目名称:GATEvolution,代码行数:101,代码来源:WordOpenXML.cs


注:本文中的DocumentFormat.OpenXml.Packaging.MainDocumentPart.GetPartById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。