C\#Word 페이지 마다 배경 설정
사고:머 릿 말 에 모양 이나 그림 을 추가 하고 모양 이나 그림 을 평평 하 게 펴 서(즉,모양 이나 그림 크기 를 페이지 크기 로 설정 하 는 것)전체 페이지 에 보 냅 니 다.배경 을 추가 할 때 모양 을 추가 하고 모양 색 을 설정 하여 단색 배경 효과 로 설정 합 니 다.그림 추가 로 그림 배경 효 과 를 실현 합 니 다.
이번 프로그램 운영 환경 은 다음 과 같다.Net Framework 4.5.1
서로 다른 배경 을 설정 할 때 다음 과 같은 두 가지 상황 으로 나 뉜 다.
1.첫 페이지 배경 과 다른 페이지 만 설정
1.1 순수한 배경 설정
【C#】
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace DifferentBackground1
{
class Program
{
static void Main(string[] args)
{
// Word
Document doc = new Document();
doc.LoadFromFile(" .docx");
//
Section section = doc.Sections[0];
//
section.PageSetup.DifferentFirstPageHeaderFooter = true;
//
HeaderFooter firstpageheader = section.HeadersFooters.FirstPageFooter;//
firstpageheader.Paragraphs.Clear();// ( )
Paragraph firstpara = firstpageheader.AddParagraph();//
float width = section.PageSetup.PageSize.Width;// 、
float height = section.PageSetup.PageSize.Height;
ShapeObject shape = firstpara.AppendShape(width, height, ShapeType.Rectangle);//
shape.BehindText = true;//
shape.HorizontalAlignment = ShapeHorizontalAlignment.Center;// ,
shape.VerticalOrigin = VerticalOrigin.TopMarginArea;
shape.FillColor = Color.LightBlue;//
//
HeaderFooter otherheader = section.HeadersFooters.Header;
otherheader.Paragraphs.Clear();
Paragraph otherpara = otherheader.AddParagraph();
ShapeObject shape1 = otherpara.AppendShape(width, height, ShapeType.Rectangle);
shape1.BehindText = true;
shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
shape1.VerticalOrigin = VerticalOrigin.TopMarginArea;
shape1.FillColor = Color.Pink;
//
doc.SaveToFile("ColorBackground1.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("ColorBackground1.docx");
}
}
}
【VB.NET】
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace DifferentBackground1
Class Program
Private Shared Sub Main(args As String())
' Word
Dim doc As New Document()
doc.LoadFromFile(" .docx")
'
Dim section As Section = doc.Sections(0)
'
section.PageSetup.DifferentFirstPageHeaderFooter = True
'
Dim firstpageheader As HeaderFooter = section.HeadersFooters.FirstPageFooter
'
firstpageheader.Paragraphs.Clear()
' ( )
Dim firstpara As Paragraph = firstpageheader.AddParagraph()
'
Dim width As Single = section.PageSetup.PageSize.Width
' 、
Dim height As Single = section.PageSetup.PageSize.Height
Dim shape As ShapeObject = firstpara.AppendShape(width, height, ShapeType.Rectangle)
'
shape.BehindText = True
'
shape.HorizontalAlignment = ShapeHorizontalAlignment.Center
' ,
shape.VerticalOrigin = VerticalOrigin.TopMarginArea
shape.FillColor = Color.LightBlue
'
'
Dim otherheader As HeaderFooter = section.HeadersFooters.Header
otherheader.Paragraphs.Clear()
Dim otherpara As Paragraph = otherheader.AddParagraph()
Dim shape1 As ShapeObject = otherpara.AppendShape(width, height, ShapeType.Rectangle)
shape1.BehindText = True
shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center
shape1.VerticalOrigin = VerticalOrigin.TopMarginArea
shape1.FillColor = Color.Pink
'
doc.SaveToFile("ColorBackground1.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("ColorBackground1.docx")
End Sub
End Class
End Namespace
1.2 그림 배경 설정【C#】
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace DifferentBackground1
{
class Program
{
static void Main(string[] args)
{
// Word
Document doc = new Document();
doc.LoadFromFile(" .docx");
//
Section section = doc.Sections[0];
//
section.PageSetup.DifferentFirstPageHeaderFooter = true;
HeaderFooter firstpageheader = section.HeadersFooters.FirstPageFooter;//
firstpageheader.Paragraphs.Clear();// ( )
Paragraph firstpara = firstpageheader.AddParagraph();//
// 、
float width = section.PageSetup.PageSize.Width;
float height = section.PageSetup.PageSize.Height;
//
DocPicture pic0 = firstpara.AppendPicture("1.png");
pic0.TextWrappingStyle = TextWrappingStyle.Behind;
pic0.HorizontalAlignment = ShapeHorizontalAlignment.Center;
pic0.VerticalOrigin = VerticalOrigin.TopMarginArea;
pic0.Width = width;
pic0.Height = height;
//
HeaderFooter otherheader = section.HeadersFooters.Header;
otherheader.Paragraphs.Clear();
Paragraph otherpara = otherheader.AddParagraph();
DocPicture pic1 = otherpara.AppendPicture("2.png");
pic1.TextWrappingStyle = TextWrappingStyle.Behind;
pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
pic1.VerticalOrigin = VerticalOrigin.TopMarginArea;
pic1.Width = width;
pic1.Height = height;
//
doc.SaveToFile("ImageBackground1.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("ImageBackground1.docx");
}
}
}
【VB.NET】
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace DifferentBackground1
Class Program
Private Shared Sub Main(args As String())
' Word
Dim doc As New Document()
doc.LoadFromFile(" .docx")
'
Dim section As Section = doc.Sections(0)
'
section.PageSetup.DifferentFirstPageHeaderFooter = True
Dim firstpageheader As HeaderFooter = section.HeadersFooters.FirstPageFooter
'
firstpageheader.Paragraphs.Clear()
' ( )
Dim firstpara As Paragraph = firstpageheader.AddParagraph()
'
' 、
Dim width As Single = section.PageSetup.PageSize.Width
Dim height As Single = section.PageSetup.PageSize.Height
'
Dim pic0 As DocPicture = firstpara.AppendPicture("1.png")
pic0.TextWrappingStyle = TextWrappingStyle.Behind
pic0.HorizontalAlignment = ShapeHorizontalAlignment.Center
pic0.VerticalOrigin = VerticalOrigin.TopMarginArea
pic0.Width = width
pic0.Height = height
'
Dim otherheader As HeaderFooter = section.HeadersFooters.Header
otherheader.Paragraphs.Clear()
Dim otherpara As Paragraph = otherheader.AddParagraph()
Dim pic1 As DocPicture = otherpara.AppendPicture("2.png")
pic1.TextWrappingStyle = TextWrappingStyle.Behind
pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center
pic1.VerticalOrigin = VerticalOrigin.TopMarginArea
pic1.Width = width
pic1.Height = height
'
doc.SaveToFile("ImageBackground1.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("ImageBackground1.docx")
End Sub
End Class
End Namespace
2.여러 페이지 의 배경 이 다 르 게 설정주:여러 페이지 에 서로 다른 배경 을 설정 할 때 서로 다른 섹 션 의 머 릿 말 을 가 져 와 서 설정 해 야 합 니 다.이번 프로그램 환경 에서 사용 하 는 소스 문 서 는 여러 섹 션 을 설정 하 였 습 니 다.수 동 으로 섹 션 을 설정 하려 면 코드 를 참고 하 십시오.
document.Sections[0].Paragraphs[0].InsertSectionBreak(SectionBreakType.NoBreak);
2.1 순수한 배경 설정【C#】
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace DifferentBackground2
{
class Program
{
static void Main(string[] args)
{
// Word
Document doc = new Document();
doc.LoadFromFile(" .docx");
//
Section section1 = doc.Sections[0];
// 、
float width = section1.PageSetup.PageSize.Width;
float height = section1.PageSetup.PageSize.Height;
//
HeaderFooter header1 = section1.HeadersFooters.Header;
header1.Paragraphs.Clear();
Paragraph para1 = header1.AddParagraph();
ShapeObject shape1 = para1.AppendShape(width, height, ShapeType.Rectangle);//
shape1.BehindText = true;//
shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center;// ,
shape1.VerticalOrigin = VerticalOrigin.TopMarginArea;
shape1.FillColor = Color.LightSalmon;//
//
Section section2 = doc.Sections[1];
HeaderFooter header2 = section2.HeadersFooters.Header;
header2.Paragraphs.Clear();
Paragraph para2 = header2.AddParagraph();
ShapeObject shape2 = para2.AppendShape(width, height, ShapeType.Rectangle);//
shape2.BehindText = true;//
shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center;// ,
shape2.VerticalOrigin = VerticalOrigin.TopMarginArea;
shape2.FillColor = Color.Moccasin;//
//
Section section3 = doc.Sections[2];
HeaderFooter header3 = section3.HeadersFooters.Header;
header3.Paragraphs.Clear();
Paragraph para3 = header3.AddParagraph();
ShapeObject shape3 = para3.AppendShape(width, height, ShapeType.Rectangle);//
shape3.BehindText = true;//
shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center;// ,
shape3.VerticalOrigin = VerticalOrigin.TopMarginArea;
shape3.FillColor = Color.LawnGreen;//
//
doc.SaveToFile("ColorBackground2.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("ColorBackground2.docx");
}
}
}
【VB.NET】
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace DifferentBackground2
Class Program
Private Shared Sub Main(args As String())
' Word
Dim doc As New Document()
doc.LoadFromFile(" .docx")
'
Dim section1 As Section = doc.Sections(0)
' 、
Dim width As Single = section1.PageSetup.PageSize.Width
Dim height As Single = section1.PageSetup.PageSize.Height
'
Dim header1 As HeaderFooter = section1.HeadersFooters.Header
header1.Paragraphs.Clear()
Dim para1 As Paragraph = header1.AddParagraph()
Dim shape1 As ShapeObject = para1.AppendShape(width, height, ShapeType.Rectangle)
'
shape1.BehindText = True
'
shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center
' ,
shape1.VerticalOrigin = VerticalOrigin.TopMarginArea
shape1.FillColor = Color.LightSalmon
'
'
Dim section2 As Section = doc.Sections(1)
Dim header2 As HeaderFooter = section2.HeadersFooters.Header
header2.Paragraphs.Clear()
Dim para2 As Paragraph = header2.AddParagraph()
Dim shape2 As ShapeObject = para2.AppendShape(width, height, ShapeType.Rectangle)
'
shape2.BehindText = True
'
shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center
' ,
shape2.VerticalOrigin = VerticalOrigin.TopMarginArea
shape2.FillColor = Color.Moccasin
'
'
Dim section3 As Section = doc.Sections(2)
Dim header3 As HeaderFooter = section3.HeadersFooters.Header
header3.Paragraphs.Clear()
Dim para3 As Paragraph = header3.AddParagraph()
Dim shape3 As ShapeObject = para3.AppendShape(width, height, ShapeType.Rectangle)
'
shape3.BehindText = True
'
shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center
' ,
shape3.VerticalOrigin = VerticalOrigin.TopMarginArea
shape3.FillColor = Color.LawnGreen
'
'
doc.SaveToFile("ColorBackground2.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("ColorBackground2.docx")
End Sub
End Class
End Namespace
2.2 그림 배경 설정【C#】
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace DifferentBackground2
{
class Program
{
static void Main(string[] args)
{
// Word
Document doc = new Document();
doc.LoadFromFile(" .docx");
//
Section section1 = doc.Sections[0];
//
HeaderFooter header1 = section1.HeadersFooters.Header;
header1.Paragraphs.Clear();
Paragraph para1 = header1.AddParagraph();
DocPicture pic1 = para1.AppendPicture("1.png");
pic1.TextWrappingStyle = TextWrappingStyle.Behind;
pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
pic1.VerticalOrigin = VerticalOrigin.TopMarginArea;
float width = section1.PageSetup.PageSize.Width;
float height = section1.PageSetup.PageSize.Height;
pic1.Width = width;
pic1.Height = height;
//
Section section2 = doc.Sections[1];
HeaderFooter header2 = section2.HeadersFooters.Header;
header2.Paragraphs.Clear();
Paragraph para2 = header2.AddParagraph();
DocPicture pic2 = para2.AppendPicture("2.png");
pic2.TextWrappingStyle = TextWrappingStyle.Behind;
pic2.HorizontalAlignment = ShapeHorizontalAlignment.Center;
pic2.VerticalOrigin = VerticalOrigin.TopMarginArea;
pic2.Width = width;
pic2.Height = height;
//
Section section3 = doc.Sections[2];
HeaderFooter header3 = section3.HeadersFooters.Header;
header3.Paragraphs.Clear();
Paragraph para3 = header3.AddParagraph();
DocPicture pic3 = para3.AppendPicture("3.png");
pic3.TextWrappingStyle = TextWrappingStyle.Behind;
pic3.HorizontalAlignment = ShapeHorizontalAlignment.Center;
pic3.VerticalOrigin = VerticalOrigin.TopMarginArea;
pic3.Width = width;
pic3.Height = height;
//
doc.SaveToFile("ImageBackground2.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("ImageBackground2.docx");
}
}
}
【VB.NET】
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace DifferentBackground2
Class Program
Private Shared Sub Main(args As String())
' Word
Dim doc As New Document()
doc.LoadFromFile(" .docx")
'
Dim section1 As Section = doc.Sections(0)
'
Dim header1 As HeaderFooter = section1.HeadersFooters.Header
header1.Paragraphs.Clear()
Dim para1 As Paragraph = header1.AddParagraph()
Dim pic1 As DocPicture = para1.AppendPicture("1.png")
pic1.TextWrappingStyle = TextWrappingStyle.Behind
pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center
pic1.VerticalOrigin = VerticalOrigin.TopMarginArea
Dim width As Single = section1.PageSetup.PageSize.Width
Dim height As Single = section1.PageSetup.PageSize.Height
pic1.Width = width
pic1.Height = height
'
Dim section2 As Section = doc.Sections(1)
Dim header2 As HeaderFooter = section2.HeadersFooters.Header
header2.Paragraphs.Clear()
Dim para2 As Paragraph = header2.AddParagraph()
Dim pic2 As DocPicture = para2.AppendPicture("2.png")
pic2.TextWrappingStyle = TextWrappingStyle.Behind
pic2.HorizontalAlignment = ShapeHorizontalAlignment.Center
pic2.VerticalOrigin = VerticalOrigin.TopMarginArea
pic2.Width = width
pic2.Height = height
'
Dim section3 As Section = doc.Sections(2)
Dim header3 As HeaderFooter = section3.HeadersFooters.Header
header3.Paragraphs.Clear()
Dim para3 As Paragraph = header3.AddParagraph()
Dim pic3 As DocPicture = para3.AppendPicture("3.png")
pic3.TextWrappingStyle = TextWrappingStyle.Behind
pic3.HorizontalAlignment = ShapeHorizontalAlignment.Center
pic3.VerticalOrigin = VerticalOrigin.TopMarginArea
pic3.Width = width
pic3.Height = height
'
doc.SaveToFile("ImageBackground2.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("ImageBackground2.docx")
End Sub
End Class
End Namespace
C\#Word 의 서로 다른 페이지 에 서로 다른 배경 을 설정 하 는 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 C\#Word 에 배경 내용 을 설정 하 는 것 은 예전 의 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 부 탁 드 리 겠 습 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.