NuGet을 통해 설치됨
PM> Install-Package Spire.Doc
관련된 링크들
Word 문서의 이미지는 텍스트 내용과 밀접한 관련이 있는 경우가 많습니다. 텍스트로 가득한 문서에 비해 이미지가 포함된 문서는 더 설명적이고 매력적입니다. 이 기사에서는 프로그래밍 방식으로 방법을 배웁니다 Word 문서에 이미지 삽입 Spire.Doc for .NET사용합니다. 이 전문적인 Word 라이브러리를 사용하면 다음과 같은 작업도 할 수 있습니다 이미지 크기, 위치, 배치 스타일을 설정합니다.
Spire.Doc for .NET 설치
먼저 .NET 프로젝트의 참조로 Spire.Doc for .NET 패키지에 포함된 DLL 파일을 추가해야 합니다. DLL 파일은 이 링크에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.
PM> Install-Package Spire.Doc
Word 문서에 이미지 삽입 및 배치 스타일 설정
Spire.Doc for .NET In Line with Text, Square, Tight, Through, Top and Bottom, Behind the Text 및 In Front of Text와 같은 일반적인 래핑 스타일을 지원합니다. 다음은 이미지를 삽입하고 배치 스타일을 설정하는 자세한 단계입니다.
- 문서 인스턴스를 만듭니다.
- Document.LoadFromFile() 메서드를 사용하여 샘플 Word 문서를 로드합니다.
- Document.Sections[] 속성을 사용하여 Word 문서의 첫 번째 섹션을 가져옵니다.
- Section.Paragraphs[] 속성을 사용하여 섹션의 지정된 단락을 가져옵니다.
- Paragraph.AppendPicture() 메서드를 사용하여 이미지를 로드하고 지정된 단락에 이미지를 삽입합니다.
- DocPicture.TextWrappingType 속성을 사용하여 이미지의 래핑 스타일을 설정합니다.
- Document.SaveToFile() 메서드를 사용하여 문서를 다른 파일에 저장합니다.
- C#
- VB.NET
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace WordImage
{
class ImageinWord
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.LoadFromFile("input.docx");
//Get the first section
Section section = document.Sections[0];
//Get two specified paragraphs
Paragraph para1 = section.Paragraphs[5];
Paragraph para2 = section.Paragraphs[9];
//Insert images in the specified paragraphs
DocPicture Pic1 = para1.AppendPicture(Image.FromFile(@"C:\Users\Administrator\Desktop\pic1.jpg"));
DocPicture Pic2 = para2.AppendPicture(Image.FromFile(@"C:\Users\Administrator\Desktop\pic2.png"));
//Set wrapping styles to Square and Inline respectively
Pic1.TextWrappingStyle = TextWrappingStyle.Square;
Pic2.TextWrappingStyle = TextWrappingStyle.Inline;
//Save the document to file
document.SaveToFile("InsertImage.docx", FileFormat.Docx);
}
}
}

Word 문서의 지정된 위치에 이미지 삽입
Spire.Doc for .NET에서 제공하는 DocPicture.HorizontalPosition 및 DocPicture.VerticalPosition 속성을 사용하면 지정된 위치에 이미지를 삽입할 수 있습니다. 자세한 단계는 다음과 같습니다.
- 문서 인스턴스를 만듭니다.
- Document.LoadFromFile() 메서드를 사용하여 샘플 Word 문서를 로드합니다.
- Document.Sections[] 속성을 사용하여 Word 문서의 첫 번째 섹션을 가져옵니다.
- Section.Paragraphs[] 속성을 사용하여 섹션의 지정된 단락을 가져옵니다.
- Paragraph.AppendPicture() 메서드를 사용하여 이미지를 로드하고 문서에 이미지를 삽입합니다.
- DocPicture.HorizontalPosition 및 DocPicture.VerticalPosition 속성을 사용하여 이미지의 가로 및 세로 위치를 설정합니다.
- DocPicture.Width 및 DocPicture.Height 속성을 사용하여 이미지의 높이와 너비를 설정합니다.
- DocPicture.TextWrappingType 속성을 사용하여 이미지의 래핑 스타일을 설정합니다.
- Document.SaveToFile() 메서드를 사용하여 문서를 다른 파일에 저장합니다.
- C#
- VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace InsertImage
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.LoadFromFile("input.docx");
//Get the first section
Section section = document.Sections[0];
//Load an image and insert it to the document
DocPicture picture = section.Paragraphs[0].AppendPicture(Image.FromFile(@"C:\Users\Administrator\Desktop\pic.jpg"));
//Set the position of the image
picture.HorizontalPosition = 90.0F;
picture.VerticalPosition = 50.0F;
//Set the size of the image
picture.Width = 150;
picture.Height = 150;
//Set the wrapping style to Behind
picture.TextWrappingStyle = TextWrappingStyle.Behind;
// Save the document to file
document.SaveToFile("Insert.docx", FileFormat.Docx);
}
}
}

임시 라이센스 신청
생성된 문서에서 평가 메시지를 제거하고 싶거나, 기능 제한을 없애고 싶다면 30일 평가판 라이센스 요청 자신을 위해.