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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM