全部代码:
using System;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Extract_image_from_word
{
class Program
{
static void Main(string[] args)
{
Document document = new Document("法国景点.docx");
int index = 0;
foreach (Section section in document.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
{
foreach (DocumentObject docObject in paragraph.ChildObjects)
{
if (docObject.DocumentObjectType == DocumentObjectType.Picture)
{
DocPicture picture = docObject as DocPicture;
String imageName = String.Format(@"imagesImage-{0}.png", index);
picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
index++;
}
}
}
}
}
}
}
总结:
这里我使用的是E-iceblue公司的免费 word 组件,它除了可以从文档中提取图片,还可以提取文本,这里我只写了提取图片的,提取文本的也差不多,如有需要可以留言。
注:相关教程知识阅读请移步到c#教程频道。











