Skip to content
  • 首页
  • 留言
  • 关于

Share the joys of programming and technology

使用 Open XML SDK中的类以编程方式往演示文稿中指定的幻灯片插入图片

使用 Open XML SDK中的类以编程方式往演示文稿中指定的幻灯片插入图片

2021年2月16日 liyanliang Comments 0 Comment
阅读次数: 120

本文演示如何使用 Open XML SDK中的类以编程方式往演示文稿中指定的幻灯片插入图片。

       public static void AddImage(string file, int slideIndex, string image, long OffsetX = 0, long OffsetY = 0, long ExtentsX = 1000000, long ExtentsY = 1000000)
        {
            using (var presentation = PresentationDocument.Open(file, true))
            {
                SlidePart slidePart = GetSlidePartbyIndex(presentation, slideIndex);

                var part = slidePart
                    .AddImagePart(ImagePartType.Png);

                using (var stream = File.OpenRead(image))
                {
                    part.FeedData(stream);
                }

                var tree = slidePart
                    .Slide
                    .Descendants<DocumentFormat.OpenXml.Presentation.ShapeTree>()
                    .First();

                var picture = new DocumentFormat.OpenXml.Presentation.Picture();

                picture.NonVisualPictureProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureProperties();
                picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties
                {
                    Name = "My Shape",
                    Id = (UInt32)tree.ChildElements.Count - 1
                });

                var nonVisualPictureDrawingProperties = new DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties();
                nonVisualPictureDrawingProperties.Append(new DocumentFormat.OpenXml.Drawing.PictureLocks()
                {
                    NoChangeAspect = true
                });
                picture.NonVisualPictureProperties.Append(nonVisualPictureDrawingProperties);
                picture.NonVisualPictureProperties.Append(new DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties());

                var blipFill = new DocumentFormat.OpenXml.Presentation.BlipFill();
                var blip1 = new DocumentFormat.OpenXml.Drawing.Blip()
                {
                    Embed = slidePart.GetIdOfPart(part)
                };
                var blipExtensionList1 = new DocumentFormat.OpenXml.Drawing.BlipExtensionList();
                var blipExtension1 = new DocumentFormat.OpenXml.Drawing.BlipExtension()
                {
                    Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
                };
                var useLocalDpi1 = new DocumentFormat.OpenXml.Office2010.Drawing.UseLocalDpi()
                {
                    Val = false
                };
                useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
                blipExtension1.Append(useLocalDpi1);
                blipExtensionList1.Append(blipExtension1);
                blip1.Append(blipExtensionList1);
                var stretch = new DocumentFormat.OpenXml.Drawing.Stretch();
                stretch.Append(new DocumentFormat.OpenXml.Drawing.FillRectangle());
                blipFill.Append(blip1);
                blipFill.Append(stretch);
                picture.Append(blipFill);

                picture.ShapeProperties = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
                picture.ShapeProperties.Transform2D = new DocumentFormat.OpenXml.Drawing.Transform2D();
                picture.ShapeProperties.Transform2D.Append(new DocumentFormat.OpenXml.Drawing.Offset
                {
                    X = OffsetX,
                    Y = OffsetY,
                });
                picture.ShapeProperties.Transform2D.Append(new DocumentFormat.OpenXml.Drawing.Extents
                {
                    Cx = ExtentsX,
                    Cy = ExtentsY,
                });
                picture.ShapeProperties.Append(new DocumentFormat.OpenXml.Drawing.PresetGeometry
                {
                    Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle
                });

                tree.Append(picture);
            }
        }

相关文章

  • OpenGL 几何着色器的应用OpenGL 几何着色器的应用
  • OpenGL实现多光源-附项目源码OpenGL实现多光源-附项目源码
  • 算法:寻找异常数字算法:寻找异常数字
  • 调用另外一个项目中的函数-设计模式解耦调用另外一个项目中的函数-设计模式解耦
  • WinDbg检查内存泄漏WinDbg检查内存泄漏
  • LoadLibrary和GetProcAddress获取另一个项目中的函数LoadLibrary和GetProcAddress获取另一个项目中的函数

C#
Open XML

Post navigation

PREVIOUS
RGB的CString格式转换为COLORREF
NEXT
ObjectARX开发视频教程(C++)-创建模态对话框绘制直线

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

近期文章

  • ANR崩溃日志查看方法
  • 通过数学方法来计算short类型的变量w的低八位x和高八位
  • 3dTiles数据解析
  • Games101和Games202脑图汇总
  • LearnOpenGL脑图汇总
  • IBL计算总结
  • C++实现一个简单的语言解释器
  • OpenGL-法线贴图(Normal Mapping)
  • OpenGL-卡通着色(Cartoon)
  • OpenGL几何着色器实现贝塞尔曲线
  • WinDbg检查内存泄漏
  • OpenGL雾化效果实现-每像素雾化
  • OpenGL实现billboard效果(CPU)
  • 算法:寻找异常数字
  • OpenGL 几何着色器的应用
  • Midas XD-构件详图开发
  • Midas XD-选筋助手开发
  • Civil Designer开发-检测规范自动生成控制截面
  • Civil Designer开发-公路桥梁承载能力检算评定
  • Midas W-满堂支架快速建模助手开发

全站热点

  • C++编写的情人节小程序 (2,078)
  • 提取最小封闭区域 (1,692)
  • Modern OpenGL绘制圆柱体 (1,604)
  • OpenGL开发环境搭建-GLFW与GLAD配置 超详细 (1,455)
  • 截面特性计算程序-附源码 (1,287)
  • OpenGL绘制旋转立方体 (1,103)
  • 判断一个点是否在闭合区域内 (1,031)
  • WordPress分页插件 – WP-PageNavi的使用(替换现有脚本) (947)
  • OpenGL实现billboard效果(CPU) (864)
  • Midas W-满堂支架快速建模助手开发 (832)
  • 从DLL中动态加载一个函数:LoadLibrary和GetProcAddress的使用 (746)
  • Midas XD [错误] 右侧挡土墙的最下端深度必须小于地基的最下端深度 (707)
  • 两跨连续梁影响线绘制-附源码 (685)
  • 土木想往土木软件开发方向发展,应该如何准备 (678)
  • OpenGL几何着色器实现贝塞尔曲线 (662)
  • 通过Spy++抓取窗口以查询对话框id (611)
  • 使用ODA数据库出现 “ODA_ASSUME”: 找不到标识符的错误 (547)
  • #pragma message 编译时提示信息 (525)
  • OpenGL雾化效果实现-每像素雾化 (507)
  • midas XD2020的开发 (472)

分类

  • C# (3)
  • C++ (19)
  • GIS (1)
  • MFC (3)
  • ObjectARX (2)
  • OpenGL (11)
  • Revit开发 (1)
  • 学习笔记 (2)
  • 岩土 (2)
  • 算法 (1)
  • 结构设计 (7)
  • 职场生涯 (1)
  • 计算几何 (3)

归档

  • 2024 年 12 月 (1)
  • 2024 年 10 月 (1)
  • 2024 年 9 月 (1)
  • 2023 年 3 月 (2)
  • 2022 年 10 月 (1)
  • 2022 年 3 月 (1)
  • 2022 年 2 月 (1)
  • 2022 年 1 月 (5)
  • 2021 年 11 月 (7)
  • 2021 年 6 月 (3)
  • 2021 年 5 月 (2)
  • 2021 年 3 月 (2)
  • 2021 年 2 月 (8)
  • 2021 年 1 月 (18)

标签

3dtiles anr Bezier Curves BillBoard C++ CDN CivilDesigner DLL EasyX fog glTF MFC Midas W Midas XD NormalMapping ObjectARX ODA OpenGL OpenXML Open XML PBR revit WinDbg 基坑设计 影响线 截面特性 桥梁 桥梁检测 桥梁设计 算法 计算几何 设计模式

书签

  • 李燕良的CSDN
  • 崔济东的博客
  • C++爱好者博客
  • 陈学伟的博客
  • 贾苏的博客
  • 陈睦锋的博客
  • 孙勇的博客

统计

  • 0
  • 253
  • 130
  • 472
  • 198
  • 266,571
  • 76,760

实时访问地域

© 2025   liyanliang.net Copyright. All Rights Reserved.