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

  

相关推荐:

如何利用Python Django的Include标签拆分大型模板文件?

{%include%}能拆分模板但需注意变量作用域、路径规则(仅从templates根目录解析)和循环中重复渲染的性能问题,非万能解法。 直接说结论:用{%include%}能拆分模板,但必须注意变量作用域、路径解析规则和循环内重复渲染的性能陷阱——它不是“无脑切文件”的万能解药。 include标...

如何使用 spaCy 精确提取句子中的多个独立日期

本文介绍如何解决spacy默认将“from…to…”结构识别为单个date实体的问题,通过后处理拆分策略(如按“to”“until”等连接词分割),准确提取出每个独立日期字符串。 本文介绍如何解决spacy默认将“from…to…”结构识别为单个date实体的问题,通过后处理拆分策略(如按“to”“...

如何在 spaCy 中精准提取句子中的多个独立日期

本文介绍如何解决spacy默认将“from…to…”类日期范围识别为单个date实体的问题,通过后处理拆分实现粒度更细的独立日期提取,并支持混合句式与多日期场景。 本文介绍如何解决spacy默认将“from…to…”类日期范围识别为单个date实体的问题,通过后处理拆分实现粒度更细的独立日期提取,并...