2013-07-12 3 views
0

Excel 매크로를 생성하려고하는데 어떤 방향으로 가고 싶습니다. 내가하려는 것은 5 개의 XML 파일에서 데이터를 가져와 새로운 통합 문서에 넣은 다음 결과 데이터를 선 그래프 형식으로 그래프로 표시하는 것입니다. XML 파일의 데이터는 모두 5 개 개의 파일에서 동일하며 아래에 표시되는 형식으로되어 있습니다 :XML 데이터 수정을위한 Excel 매크로

XML 테이블로 Excel에서 열 때
<Sample Secs="25313"> 
    <Pout>215280</Pout> 
</Sample> 
<Sample Secs="25562"> 
    <Pout>233627</Pout> 
</Sample> 

어느, 표시됩니다 같은 :

25313 215280 
25562 233627 

"Secs"와 "Pout"의 헤더를 가지고있다. "Secs"열은 A 열의 5 개 파일 모두에서 공통적으로 사용되며 고유 한 데이터는 B 열에있는 "Pout"열에 있습니다. B 열의 각 파일에는 약 1500 개의 데이터 요소가 있습니다. 달성하고자하는 것은 5 개의 XML 파일을 모두 열고, 각 파일에서 가져온 고유 한 데이터를 가져온 다음 데이터를 그래프로 표시하는 것입니다. (이것은 일반적인 같이) (5 개) 파일 중 하나에서 오는 "는 초"에 대한 데이터를

Secs Pout1 Pout2 Pout3 Pout4 Pout5 

및 열 B 데이터가되는 : 그래프 전에, 나는 새로운 Excel 통합 문서는 다음과 같이 포맷 봐 싶습니다 각각의 Pout # 컬럼에 넣는다.

Excel VBA에서이 작업을 수행 할 수있는 방법이 있습니까?이 작업을 올바르게 설정하는 방법은 무엇입니까?

+0

지금까지 어떤 코딩을 했습니까? – whytheq

답변

0

자세한 내용은 this MSDN page을 참조하십시오.

Option Explicit 

    Private Sub LoadXmlData() 

    Dim xmlDoc As New DOMDocument60 
    Dim sSecs As String, sPout As String 
    Dim iNodes As Integer, i As Integer, t As Integer 
    Dim sPath1 As String, sPath2 As String, sPath3 As String, _ 
     sPath4 As String, sPath5 As String, sTempPath As String 

    Range("A1").Value2 = "Secs" 
    'Set the file paths of your xml documents here 

    sPath1 = "" 
    sPath2 = "" 
    sPath3 = "" 
    sPath4 = "" 
    sPath5 = "" 

    For t = 0 To 4 
     Select Case t 
      Case 0 
       sTempPath = sPath1 
      Case 1 
       sTempPath = sPath2 
      Case 2 
       sTempPath = sPath3 
      Case 3 
       sTempPath = sPath4 
      Case 4 
       sTempPath = sPath5 
     End Select 

     xmlDoc.Load (sTempPath) 
     iNodes = xmlDoc.DocumentElement.ChildNodes.Length 

     'Fill in the first column with the values from the attribute Secs 
     'Only do it once because the values are the same in each file 
     If t = 0 Then 
      For i = 0 To iNodes - 1 
       Range("A" & i + 2).Value2 = xmlDoc.DocumentElement.ChildNodes.Item(i).Attributes.Item(0).Text 
      Next i 
     End If 

     'Fill in the Pout column 
     Cells(1, t + 1).Value2 = "Pout" & t + 1 
     For i = 0 To iNodes - 1 
      Cells(i + 2, t + 1).Value2 = xmlDoc.DocumentElement.ChildNodes.Item(i).nodeTypedValue 
     Next i 
    Next t 

End Sub