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; }
版权声明:本文为zhao-yi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。