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;
        }

  

转载于:https://www.cnblogs.com/zhao-yi/p/8385759.html

    原文作者:superXX07
    原文地址: https://blog.csdn.net/weixin_30786657/article/details/98001758
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞