2013-05-15 2 views
1

오픈 XML을 처음 사용하려고합니다. 튜토리얼은 여기 http://www.codeproject.com/Articles/36694/Creation-of-a-Word-2007-document-using-the-Open-XM에서 찾을 수 있습니다. 나는 새로운 WordprocessingDocument 등의 변수를 선언 할 때 나는 오류가 나타납니다 :OpenXML을 사용하여 WordprocessingDocument의 새 인스턴스를 선언하는 중

"Type WordprocessingDocument.Create is undefined".

Imports DocumentFormat.OpenXml 
Imports DocumentFormat.OpenXml.Wordprocessing 
Imports DocumentFormat.OpenXml.Packaging 

Partial Class test 

Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
    makedoc("file.docx") 
End Sub 

Private Sub makedoc(ByVal documentfilename As String) 
    Using mydoc As New WordprocessingDocument.Create(documentfilename, WordprocessingDocumentType.Document) 
     Dim mainPart As MainDocumentPart = mydoc.AddMainDocumentPart() 
     'Create Document tree for simple document. 
     mainPart.Document = New Document() 
     'Create Body (this element contains 
     'other elements that we want to include 
     Dim body As New Body() 
     'Create paragraph 
     Dim paragraph As New Paragraph() 
     Dim run_paragraph As New Run() 
     ' we want to put that text into the output document 
     Dim text_paragraph As New Text("Hello World!") 
     'Append elements appropriately. 
     run_paragraph.Append(text_paragraph) 
     paragraph.Append(run_paragraph) 
     body.Append(paragraph) 
     mainPart.Document.Append(body) 
     ' Save changes to the main document part. 
     mainPart.Document.Save() 
    End Using 

답변

1

이 같은 WordDocumentProcessing의 새로운 인스턴스를 만들 수 없습니다. 생성자가 보호됩니다. respone에 대한

Using mydoc as WordProcessingDocument = WordProcessingDocument.Create(DocumentFileName, WordprocessingDocumentType.Document) 
    ... 
End Using 
+0

감사 :

당신은 Create 또는 Open 메서드를 호출해야합니다. 나는 원래 Create 메서드를 호출하고 오류가 발생하지 않고 그것을 제거한 후 그 오류가 발생하지 않은 것을 확인했다. 나는 단지 그것을 다시 추가하여 결과가 무엇인지 알려 줄 것입니다. –

+0

.create를 사용할 때 WordprocessingDocument.Create가 정의되지 않은 오류가 발생합니다. 가져올 다른 수업이 있습니까? –

+0

아니요, 위에서 언급 한 세 가지 수업 만 필요합니다. 이 코드는 저에게 효과적입니다. 나는 너에게 무슨 일이 일어나는 지 이해하지 못한다. – Chris

관련 문제