Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Main()
  2.  
  3. Dim Xdoc
  4.  
  5. Public sub Main()
  6.     Dim args
  7.     Dim argsCount
  8.     Set args = Wscript.Arguments
  9.     argsCount = Wscript.Arguments.Count
  10.     if (argsCount = 2) then
  11.         if (args(0) = "-h") then
  12.             Wscript.echo "You should input xml file name and doc file name"
  13.         else  
  14.             Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
  15.             Set file = objFSO.GetFile(args(0))
  16.             if not right(file.name,4) =".xml" then
  17.                 set StdErr = Wscript.StdErr
  18.                 StdErr.write "Error: Not a xml file "
  19.                 WScript.Echo args(0)
  20.             else
  21.                 Dim obj
  22.                 Dim Check
  23.                 Check = CreateDoc(obj)
  24.                 Set XDoc = CreateObject("Msxml2.DOMDocument.6.0")
  25.                 if (XDoc.Load(args(0))) then
  26.  
  27.                     Dim N
  28.                     N = 0
  29.                     for each node in XDoc.SelectNodes("//Section")
  30.                         N = N + 1
  31.                     Next
  32.                     Dim table
  33.                     Check = Init_Table(N,4,table,obj)
  34.                     Check = FillTable(table, obj)
  35.                     obj.SaveAs(args(1))
  36.                     obj.Application.Quit
  37.  
  38.                 else
  39.                     set StdErr = Wscript.StdErr
  40.                     StdErr.write "Error: Couldn't read xml file "
  41.                     WScript.Echo args(0)
  42.                 end if
  43.             end if
  44.         end if
  45.     else
  46.         Wscript.echo "You should input xml file name and doc file name "
  47.     end if
  48. end sub
  49.  
  50. Private Function Init_Table(NumRows0, NumColumns0, Table, obj)
  51.     Set myRange = obj.Range(0, 0)
  52.     Set Table = obj.Tables.Add(myRange, NumRows0, NumColumns0)
  53.     Table.AutoFitBehavior (wdAutoFitWindow)
  54.     Table.Borders.Enable = True
  55.     Init_Table = 0
  56. End Function
  57.  
  58. Private Function CreateDoc(obj)
  59.     Set obj = CreateObject("Word.Application")
  60.     obj.Visible = False
  61.     Set obj = obj.Documents.Add()
  62.     CreateDoc = 1
  63. end Function
  64.  
  65. Private Function FillTable(table, obj)
  66.     Dim T1
  67.     Dim T2
  68.     Dim T3
  69.     Dim T4
  70.     For Each Node In XDoc.SelectNodes("//Sections/*")
  71.         T4 = False
  72.         If Node.nodeName = "Section" Then
  73.             I = I + 1
  74.             N = N + 1
  75.             T1 = Node.Attributes.Item(0).text
  76.             T2 = Node.Attributes.Item(1).text
  77.             T3 = Node.Attributes.Item(2).text
  78.             For Each SymbolNode In XDoc.SelectNodes("//Symbols/*")
  79.                 If SymbolNode.Attributes.Item(1).text = Node.Attributes.Item(1).text Then
  80.                     For Each ExportNode In XDoc.SelectNodes("//Exports/*")
  81.                         If ExportNode.Attributes.Item(1).text = SymbolNode.Attributes.Item(2).text Then
  82.                             T4 = True
  83.                         End If
  84.                     Next
  85.                 End If
  86.             Next
  87.             table.Cell(N, 1).Range.text = T1
  88.             table.Cell(N, 2).Range.text = T2
  89.             table.Cell(N, 3).Range.text = T3
  90.             table.Cell(N, 4).Range.text = T4
  91.            
  92.         End If
  93.     Next
  94.     FillTable = 1
  95. end Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement