IronWord 시작하기
IronWord: .NET 용 워드 문서 라이브러리
IronWord 는 Iron Software 에서 개발한 Word 문서 라이브러리입니다. IronWord .NET 애플리케이션에서 Word 문서를 작업하는 데 필요한 강력한 기능을 제공하는 데 탁월합니다.
- Word 및 Docx 문서를 불러오고, 편집하고, 저장합니다.
PageSetup: 용지 크기, 페이지 방향, 여백 및 배경색 설정.TextRun: 텍스트 콘텐츠, 스타일, 분할, 텍스트 추가, 이미지 추가 처리.TextStyle: 글꼴 패밀리, 크기, 색상, 굵게, 이탤릭, 취소선, 밑줄, 윗주, 아래 첨자 관리.Paragraph: 텍스트 런, 이미지, 도형 추가, 스타일, 정렬, 글머리표 및 번호 목록 설정.Table: 행 추가, 셀 값 가져오기 및 설정, 행 제거, 셀 병합 등 표 구조 조작.Image: 파일 또는 스트림에서 이미지 로드, 텍스트 줄바꿈 설정, 위치 오프셋, 너비, 높이 및 기타 속성 설정.Shape: 텍스트 줄바꿈 설정, 위치 오프셋, 너비, 높이, 도형 유형 및 회전 설정.
.NET 용 Word 문서 C# 라이브러리
- DOCX 문서를 처리하는 C# 라이브러리를 다운로드하세요.
- Word 및 DOCX 문서를 생성하고 수정합니다.
- 단락, 섹션, 표와 같은 문서 구조를 추가하세요.
- 텍스트, 이미지, 도형 등의 문서 요소를 추가합니다.
- 문서 요소의 스타일을 손쉽게 지정하세요
설치
IronWord 라이브러리
IronWord 설치는 빠르고 간편합니다. 다음 명령어를 사용하여 NuGet 으로 패키지를 설치할 수 있습니다.
Install-Package IronWord
또는 IronWord 공식 NuGet 웹사이트 에서 직접 다운로드할 수도 있습니다.
설치 후에는 C# 코드 파일 상단에 using IronWord;를 추가하여 시작할 수 있습니다.
라이선스 키 적용
다음으로, License 클래스의 LicenseKey 속성에 라이센스 키를 할당하여 IronWord에 유효한 라이센스 또는 체험판 키를 적용합니다. 다음 코드를 임포트 문 바로 뒤, IronWord 메서드를 사용하기 전에 포함시키십시오.
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"
코드 예제
이제 몇 가지 코드 예제와 사용 가능한 기능들을 살펴보겠습니다.
- '파일' > '정보'를 선택하고 '변환'을 클릭합니다.
- 문서가 최신 파일 형식으로 업그레이드된다는 메시지가 표시됩니다. "확인"을 클릭하세요.
Word 및 Docx 문서 생성
생성자 중 하나를 사용하여 WordDocument 클래스를 인스턴스화하여 Word 문서를 만듭니다. 그 후, SaveAs 메서드를 사용하여 Word 문서를 내보냅니다. 예:
using IronWord;
class Program
{
static void Main()
{
// Create a new Word document
var document = new WordDocument();
// Save the document as a .docx file
document.SaveAs("example.docx");
}
}
using IronWord;
class Program
{
static void Main()
{
// Create a new Word document
var document = new WordDocument();
// Save the document as a .docx file
document.SaveAs("example.docx");
}
}
Imports IronWord
Friend Class Program
Shared Sub Main()
' Create a new Word document
Dim document = New WordDocument()
' Save the document as a .docx file
document.SaveAs("example.docx")
End Sub
End Class
이미지 추가
이미지는 단독으로 추가할 수 없습니다. 대신에, Paragraph, TableCell 또는 Section와 같은 문서 구조 중 하나에 추가해야 합니다. AddImage 메서드를 사용하여 이미지를 추가합니다. 예:
using IronWord;
using System.Drawing;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
// Add an image to a paragraph
var paragraph = section.Paragraphs.Add();
paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));
document.SaveAs("example_with_image.docx");
}
}
using IronWord;
using System.Drawing;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
// Add an image to a paragraph
var paragraph = section.Paragraphs.Add();
paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));
document.SaveAs("example_with_image.docx");
}
}
Imports IronWord
Imports System.Drawing
Friend Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = document.Sections.Add()
' Add an image to a paragraph
Dim paragraph = section.Paragraphs.Add()
paragraph.AddImage("path/to/image.jpg", New Rectangle(0, 0, 100, 100))
document.SaveAs("example_with_image.docx")
End Sub
End Class
테이블 추가
테이블을 추가하려면 테이블, 행, 열 및 테이블 셀을 만들어야 합니다. 이를 통해 각 셀이 서로 다른 스타일을 가질 수 있으므로 상당한 구성 가능성이 열립니다. 예:
using IronWord;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
var table = section.Tables.Add(3, 3); // 3x3 table
// Iterate over cells and set their content
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
}
}
document.SaveAs("example_with_table.docx");
}
}
using IronWord;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
var table = section.Tables.Add(3, 3); // 3x3 table
// Iterate over cells and set their content
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
}
}
document.SaveAs("example_with_table.docx");
}
}
Imports IronWord
Friend Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = document.Sections.Add()
Dim table = section.Tables.Add(3, 3) ' 3x3 table
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
Dim j As Integer = 0
Do While j < table.Rows(i).Cells.Count
table.Rows(i).Cells(j).Paragraphs.Add().AppendText($"Cell {i+1},{j+1}")
j += 1
Loop
Next i
document.SaveAs("example_with_table.docx")
End Sub
End Class
라이선스 및 지원 가능
IronWord 는 유료 라이브러리입니다. 하지만 여기에서 무료 평가판 라이선스를 이용할 수 있습니다.
Iron Software 에 대한 자세한 정보는 당사 웹사이트를 방문하십시오.https://ironsoftware.com/ . 더 자세한 지원이나 문의 사항이 있으시면 저희 팀에 문의해 주세요.
Iron Software 의 지원
일반적인 지원 및 기술 관련 문의는 다음 이메일 주소로 보내주시기 바랍니다:support@ironsoftware.com

