이 간단한 가이드는 C#을 사용하여 **Word에서 단락 서식을 설정하는 데 도움이 됩니다. IDE를 설정하는 세부 정보, 단계 목록 및 C#을 사용하여 MS Word 단락 서식을 변경하는 샘플 코드가 있습니다. 다양한 속성을 설명하고 단락 서식, 테두리 및 스타일의 사용자 지정을 보여줍니다.
C#를 사용하여 문단 쓰기 형식 설정을 위한 단계
- IDE를 설정하여 Aspose.Words for .NET을 사용하여 텍스트를 서식 지정합니다.
- Document 클래스를 사용하여 문단 형식을 설정하기 위한 새 Word 파일을 만듭니다.
- 위의 Word 문서를 사용하여 DocumentBuilder 클래스 객체를 만듭니다.
- 문단 형식에서 들여쓰기 및 정렬 속성 설정
- 문단 테두리 및 글꼴 설정
- 위의 문단 서식을 확인하기 위해 텍스트를 추가하세요.
- Save 서식이 지정된 텍스트가 있는 새 Word 파일
이 단계에서는 C#을 사용하여 Word 문서 단락 서식을 설정하는 방법을 설명합니다. 새 Word 문서를 만들고 DocumentBuilder 개체를 첨부하고 정렬, 왼쪽 들여쓰기, 오른쪽 들여쓰기 및 뒤의 공백을 설정하기 위한 ParagraphFormat 속성에 액세스합니다. 마찬가지로 크기, 색상 및 Bold와 같은 테두리 및 글꼴 속성을 설정할 수 있습니다.
C#을 사용하여 Microsoft Word 문단 서식을 설정하는 코드
using Aspose.Words; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
License lic = new License(); | |
lic.SetLicense("license.lic"); | |
Document document = new Document(); | |
DocumentBuilder docBuilder = new DocumentBuilder(document); | |
// Set formatting | |
ParagraphFormat paragraphFormat = docBuilder.ParagraphFormat; | |
paragraphFormat.Alignment = ParagraphAlignment.Justify; | |
paragraphFormat.LeftIndent = 45; | |
paragraphFormat.RightIndent = 45; | |
paragraphFormat.SpaceAfter = 20; | |
paragraphFormat.Borders.Horizontal.LineStyle = LineStyle.Double; | |
paragraphFormat.Style.Font.Size = 12; | |
paragraphFormat.Style.Font.Color = System.Drawing.Color.Blue; | |
paragraphFormat.Style.Font.Bold = true; | |
// Output text | |
docBuilder.Writeln("Text formatting in a Word file allows users to enhance the appearance of their documents, making them more readable and visually appealing. Common formatting options include changing the font type and size, applying bold, italics, or underline for emphasis, and adjusting text alignment (left, center, right, or justified)."); | |
docBuilder.Writeln("You can also modify line spacing, add bullet points or numbered lists, and use indentation to organize content."); | |
document.Save("Output.docx"); | |
System.Console.WriteLine("Paragraph formatted in Word file"); | |
} | |
} |
이 코드 세그먼트는 C#을 사용하여 문단 들여쓰기를 보여줍니다. 문서에 대한 DocumentBuilder 객체를 만들면 ParagraphFormat과 같은 모든 속성에 액세스할 수 있습니다. 또한 페이지 설정, 정렬, 줄 간격, 페이지 나누기, 음영, 줄 바꿈을 설정하고 필요한 경우 명령 하나로 서식을 지울 수도 있습니다.
이 문서에서는 새 Word 파일이나 기존 Word 파일의 서식을 설정하는 방법을 안내했습니다. Word 파일의 머리글과 바닥글을 제거하려면 C#을 사용하여 Word에서 머리글과 바닥글 제거의 문서를 참조하세요.