오픈 XML 워드 프로세싱을 사용하여 단락에 미리 정의 된 스타일을 추가하는 방법을 안내해 줄 수 있습니까? 포럼에서 사용할 수있는 다양한 솔루션을 시도했지만 나에게 맞는 것은 없습니다. 여기 내가 성취하고자하는 바가 있습니다 :OpenXML 워드 프로세싱 문서에 단락 스타일 (Heading1, Heading2, Head 3 Etc) 추가
// Create a document by supplying the filepath.
WordprocessingDocument wordDocument = WordprocessingDocument.Create("E:/Test/Executive.Docx", WordprocessingDocumentType.Document);
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure and add some text.
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text("Executive Summary"));
if (para.Elements<ParagraphProperties>().Count() == 0)
para.PrependChild<ParagraphProperties>(new ParagraphProperties());
// Get the ParagraphProperties element of the paragraph.
ParagraphProperties pPr = para.Elements<ParagraphProperties>().First();
// Set the value of ParagraphStyleId to "Heading3".
pPr.ParagraphStyleId = new ParagraphStyleId() { Val = "Heading1" };
StyleDefinitionPart는 StyleDefinitionsPart 여야합니다. –