要通过C#获取Word中图片的原图,可以使用Microsoft.Office.Interop.Word库来实现。以下是一个示例代码:

using Microsoft.Office.Interop.Word;

class Program
{
    static void Main(string[] args)
    {
        string filePath = "path_to_your_word_file.docx";
        Application wordApplication = new Application();
        Document wordDocument = wordApplication.Documents.Open(filePath);

        foreach (InlineShape shape in wordDocument.InlineShapes)
        {
            if (shape.Type == WdInlineShapeType.wdInlineShapePicture)
            {
                string picturePath = shape.Range.InlineShapes[1].PictureFormat.Filename;
                shape.Range.InlineShapes[1].PictureFormat.SaveAs(picturePath);
                Console.WriteLine("Saved picture: " + picturePath);
            }
        }

        wordDocument.Close();
        wordApplication.Quit();
    }
}

请确保已安装Microsoft Office并引用了Microsoft.Office.Interop.Word库。在代码中,将path_to_your_word_file.docx替换为实际的Word文件路径。程序会遍历Word文档中的所有图片,并将其保存到与原始图片相同的路径下。

通过C#获取word中图片的原图

原文地址: https://www.cveoy.top/t/topic/jbCJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录