Word控件Spire.Doc 【页面背景】教程(7) ;在 C# 中为 word 文档设置图像背景

我们已经演示了如何在 C# 中为 word 文档设置渐变背景。除了渐变背景,Spire.Doc还支持为word文档添加图片背景。本文将向您展示如何在 C# 中为 word 文档设置图像背景。

Spire.Doc for.NET 最新下载icon-default.png?t=M85Bhttps://www.evget.com/product/3368/download

第 1 步:创建一个新的 Word 文档并从文件中加载该文档。

Document document = new Document();
document.LoadFromFile("Sample.docx", FileFormat.Docx2010);

第 2 步:设置背景类型为图片。

document.Background.Type = BackgroundType.Picture;

第 3 步:从文件中加载图像。

document.Background.Picture = Image.FromFile("background.jpg");

第 4 步:将文档保存到文件中。

document.SaveToFile("Result.docx", FileFormat.Docx2010);

word文档添加图片背景的有效截图:

如何为word文档设置图像背景的完整代码:

using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace SetImageBackground
{
class Program
{
static void Main(string[] args)
{
{
Document document = new Document();
document.LoadFromFile("Sample.docx", FileFormat.Docx2010);

document.Background.Type = BackgroundType.Picture;

document.Background.Picture = Image.FromFile("background.jpg");

document.SaveToFile("Result.docx", FileFormat.Docx2010);
}

}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!感谢您的提问。针对您的问题,使用Spire.Doc实现复制doc指定页面数据存放到另一个word的大致步骤如下: 1. 加载原始Word文档,使用Document类的LoadFromFile方法可以实现。 ``` Document doc = new Document(); doc.LoadFromFile("Original.docx"); ``` 2. 获取原始Word文档指定页面的数据,可以通过Document类的Sections属性获取所有的Section对象,然后使用Section类的PageNumber属性获取指定页码的Section对象,最后使用Section类的ToText方法获取该页的文本数据。 ``` Section section = doc.Sections[1]; // 获取第一页的Section对象 string pageText = section.ToText(); // 获取第一页的文本数据 ``` 3. 创建新的Word文档,使用Document类的构造函数可以创建一个新的空白Word文档。 ``` Document newDoc = new Document(); ``` 4. 将指定页面的数据添加到新的Word文档中,可以通过Document类的AddSection方法添加一个新的Section对象,然后使用Section类的AddParagraph方法添加一个新的Paragraph对象,最后使用Paragraph类的AppendText方法添加文本数据。 ``` Section newSection = newDoc.AddSection(); Paragraph newParagraph = newSection.AddParagraph(); newParagraph.AppendText(pageText); ``` 5. 保存新的Word文档,使用Document类的SaveToFile方法可以将新的Word文档保存到指定的文件路径。 ``` newDoc.SaveToFile("New.docx", FileFormat.Docx); ``` 以上就是使用Spire.Doc实现复制doc指定页面数据存放到另一个word的大致步骤。希望对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值