当前位置:网站首页>C#/VB. Net to set solid color / gradient / picture background in word
C#/VB. Net to set solid color / gradient / picture background in word
2022-06-09 03:13:00 【InfoQ】
One 、 Set a solid background
- Create a Document Class object , Concurrent loading Word file .
- adopt Document.Background.Type Property to set the background fill mode of the document to color fill .
- adopt Document.Background.Color Property to set the background color .
- use Document.SaveToFile() Method to save a document .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Spire.Doc;
using System.Drawing;
namespace AddBackground
{
class Program
{
static void Main(string[] args)
{
// Create a Document Class object , And load Word file
Document document = new Document();
document.LoadFromFile(@"NewSample1.docx");
// Set the background fill mode of the document to color fill
document.Background.Type = Spire.Doc.Documents.BackgroundType.Color;
// Set the background color
document.Background.Color = Color.MistyRose;
// Save and open the document
document.SaveToFile("PureBackground.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("PureBackground.docx");
}
}
}Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports Spire.Doc
Imports System.Drawing
Namespace AddBackground
Class Program
Private Shared Sub Main(ByVal args() As String)
Create a Document Class object , And load Word file
Dim document As Document = New Document
document.LoadFromFile("NewSample1.docx")
' Set the background fill mode of the document to color fill
document.Background.Type = Spire.Doc.Documents.BackgroundType.Color
' Set the background color
document.Background.Color = Color.MistyRose
' Save and open the document
document.SaveToFile("PureBackground.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("PureBackground.docx")
End Sub
End Class
End Namespace
Two 、 Set gradient background
- Create a new instance document and useDocument.LoadFromFile() Method to load the instance document .
- adopt Document.Background.Type Property to set the gradient background type .
- adopt BackgroundGradient.Color1 Property to set the first gradient color .
- adopt BackgroundGradient.Color2 Property to set the second gradient color .
- adopt BackgroundGradient.ShadingVariant Property to set the shadow style and gradient effect
- useDocument.SaveToFile() Method to save a document .
using System.Drawing;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
namespace SetGradientBackground
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// establish Word file .
Document document = new Document();
// Load instance document .
document.LoadFromFile("NewSample1.docx");
// Set the gradient background type .
document.Background.Type = BackgroundType.Gradient;
BackgroundGradient Test = document.Background.Gradient;
// Set gradient color .
Test.Color1 = Color.White;
Test.Color2 = Color.LightBlue;
// Set shadow style and gradient effect .
Test.ShadingVariant = GradientShadingVariant.ShadingDown;
Test.ShadingStyle = GradientShadingStyle.Horizontal;
String result = "Result-SetGradientBackground.docx";
// Save the document .
document.SaveToFile(result, FileFormat.Docx2013);
}
}
}Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace SetGradientBackground
Public Class Form1
Inherits Form
Public Sub New()
MyBase.New
InitializeComponent
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
' establish Word file .
Dim document As Document = New Document
' Load instance document .
document.LoadFromFile("..\..\..\..\..\..\Data\Template_Docx_2.docx")
' Set the gradient background type .
document.Background.Type = BackgroundType.Gradient
Dim Test As BackgroundGradient = document.Background.Gradient
' Set the color 1 For the background , Color 2 For gradient .
Test.Color1 = Color.White
Test.Color2 = Color.LightBlue
' Set shadow style and gradient effect .
Test.ShadingVariant = GradientShadingVariant.ShadingDown
Test.ShadingStyle = GradientShadingStyle.Horizontal
Dim result As String = "Result-SetGradientBackground.docx"
' Save the document .
document.SaveToFile(result, FileFormat.Docx2013)
End Sub
End Class
End Namespace
3、 ... and 、 Set picture background
- Create and load sample documents
- adopt Document.Background.Type Property to set the background picture type
- adopt Document.Background.Picture Property to set the background picture
- use Document.SaveToFile() Method to save a document
using System.Drawing;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
namespace SetImageBackground
{
class Program
{
static void Main(string[] args)
{
// Load the document
Document document = new Document("NewSample1.docx");
// Set the background picture type .
document.Background.Type = BackgroundType.Picture;
// Set the background image
document.Background.Picture = Image.FromFile("Background.png");
// Save the document .
document.SaveToFile("ImageBackground.docx", FileFormat.Docx);
}
}
}Imports System.Drawing
Imports System.Text
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace setimagebackground
Class Program
Private Shared Sub Main(ByVal args() As String)
' load Word file
Dim document As Document = New Document("Template.docx")
' Set the background picture type .
document.Background.Type = BackgroundType.Picture
' Set the background image
document.Background.Picture = Image.FromFile("Background.png")
' Save the document .
document.SaveToFile("ImageBackground.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
边栏推荐
- Ccf-csp 201803-5 quadratic summation 30 points
- Sorting out the soft and hard decoding methods of ffmpeg
- Elderly fall prevention alarm system based on stm32+ Huawei cloud IOT [play with Huawei cloud]
- New Presto data source support, new symbol map, and release of dataease open source data visual analysis platform v1.11.0
- Go Technology Daily (2022 - 06 - 07) - go programer Development Efficiency God Summary
- RTSP/Onvif协议视频平台EasyNVR对静态文件大小的优化
- Leetcode 1185. Day of the week
- [detailed explanation of kubernetes 13] - dashboard deployment
- [Beijing Normal University] information sharing of the first and second postgraduate entrance examinations
- Foxconn suffered another blackmail attack, and a large number of unencrypted files were leaked
猜你喜欢

ERP总体介绍

FPGA初次尝试

视频边缘计算网关EasyNVR硬件以服务方式启动一直报错,如何排查及解决?

Flutter donewidget example

Leetcode 1074. Element sum is the number of submatrixes of the target value two-dimensional prefix sum

What is the network transformer for? (Ethernet network LAN LAN communication isolation filter) production plant / product schematic diagram / common products / price influencing factors

Do you know the specifications of e-commerce background permission settings!

Redis6学习笔记-第一章-Redis的介绍与环境搭建

Simple use of Wireshark

Ccf-csp 201403-3 command line options
随机推荐
视频边缘计算网关EasyNVR硬件以服务方式启动一直报错,如何排查及解决?
Ccf-csp 201412-3 call auction
Ccf-csp 201903-3 damaged RAID5 70 points to be optimized
Generation of random numbers in C language [detailed explanation]
RTSP/Onvif协议视频平台EasyNVR如何配置用户的视频流播放时长?
The easynvr hardware of the video edge computing gateway always reports an error when it is started in the service mode. How to troubleshoot and solve it?
RTSP/Onvif协议视频平台EasyNVR对静态文件大小的优化
Go Technology Daily (2022 - 06 - 07) - go programer Development Efficiency God Summary
Foxconn suffered another blackmail attack, and a large number of unencrypted files were leaked
Ccf-csp 201803-5 quadratic summation 30 points
Redis data storage
關於JS console.log() 是同步 or 异步引發的問題
Greedy method / Huffman code
qt项目添加编译报错选项
Gradle view the dependency tree of a package
Leetcode 1310. Subarray XOR query prefix and + XOR
Electron desktop development (process)
Date tool class - conversion of operation string to date and localdate, time difference between two dates, etc
Flutter donewidget example
Ccf-csp 201903-2 24:00