首先安装依赖包Spire.Doc
引用命名空间:
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Paragraph = Spire.Doc.Documents.Paragraph;
using Section = Spire.Doc.Section;
实现代码:
public static void GetPicFromDoc(string path)
{
Document document = new Document(path);
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(@"F:\test\Image-{0}.png", index);
picture.Image.Save(imageName, System.Drawing.Imaging.ImageFormat.Png);
index++;
}
}
}
}
}
- 本文标题: C#提取Word里面图片保存至本地
- 文章分类:【WinForm/WPF】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.