首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C# .NET DocX向.docx文件添加图像

C# .NET DocX向.docx文件添加图像
EN

Stack Overflow用户
提问于 2016-07-29 12:27:32
回答 1查看 9.5K关注 0票数 2

我希望使用C#中的DocX库将图像添加到Word文件中。问题是我在网上找不到任何东西。

Situation

我知道如何创建文件,也知道如何在文件中写入文本。令人遗憾的是,图书馆的文档非常少。希望你能帮我!

EN

Stack Overflow用户

回答已采纳

发布于 2016-07-29 12:44:24

DocX库包含一个示例,演示如何向文档添加图片:

代码语言:javascript
运行
复制
var myImageFullPath = "C:\tmp\sample.png";
using (DocX document = DocX.Create(@"docs\HelloWorldAddPictureToWord.docx"))
{
    // Add an image into the document.    
    Image image = document.AddImage(myImageFullPath);

    // Create a picture (A custom view of an Image).
    Picture picture = image.CreatePicture();

    // Insert a new Paragraph into the document.
    Paragraph title = document.InsertParagraph().Append("This is a test for a picture").FontSize(20).Font(new FontFamily("Comic Sans MS"));
    title.Alignment = Alignment.center;

    // Insert a new Paragraph into the document.
    Paragraph p1 = document.InsertParagraph();

    // Append content to the Paragraph
    p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky don't you think?");
    p1.AppendLine();

    p1.AppendPicture(picture);

    // Save this document.
    document.Save();
}
票数 10
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38658848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档