zoukankan      html  css  js  c++  java
  • Aspose.Words提取word文档中的图片文件

            /// <summary>
            /// 提取word中的图片
            /// </summary>
            /// <param name="filePath">word文件路径</param>
            /// <param name="savePath">保存文件路径</param>
            /// <returns></returns>
            public static List<string> ExportImageFromWordFile(string filePath, string savePath = "")
            {
                if (!File.Exists(filePath)) return new List<string>();
                if (string.IsNullOrEmpty(savePath)) savePath = AppDomain.CurrentDomain.BaseDirectory;
    
                //文件名集合
                List<string> list = new List<string>();
                //加载word
                Document doc = new Document(filePath);
                NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
                int imageIndex = 0;
                foreach (Shape shape in shapes)
                {
                    if (shape.HasImage)
                    {
                        string time = DateTime.Now.ToString("HHmmssfff");
                        //扩展名
                        string ex = FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType);
                        //文件名
                        string fileName = string.Format("{0}_{1}{2}", time, imageIndex, ex);
                        shape.ImageData.Save(savePath + fileName);
                        //添加文件到集合
                        list.Add(fileName);
                        imageIndex++;
                    }
                }
                return list;
            }
    

      

  • 相关阅读:
    Pymsql
    MySQL基础操/下
    MySQL基础操作
    前端学习之jquery/下
    前端学习之jquery
    Python之异常处理
    Python之模块和包导入
    Python之模块
    Python之面向对象上下文管理协议
    Python之面向对象slots与迭代器协议
  • 原文地址:https://www.cnblogs.com/zhao-yi/p/8385759.html
Copyright © 2011-2022 走看看