我是财务人员而不是VB脚本大师,但我想知道是否有人可以根据我的要求创建示例vb脚本。
无论谁首先提供解决方案并且解决方案在我的最终工作,都将有机会(当然付费)在我工作的地方创建更多这些自定义解决方案。它不是全职职位,而是更多的按需机会。
要求: 能够读取由逗号分隔并具有各种条目的文本文件
例如,在文本文件中...... SEC_E_All_Entities,HSII,SL_DIMENSION,READWRITE,@ IDESCENDANTS,N SEC_E_ENT_Americas,美洲,SL_DIMENSION,READ,MEMBER,N
执行以下操作......
例如:
创建SEC_E_All_Entities.XML和SEC_E_ENT_Americas.XML
例如:
在SEC_E_All_Entities.XML文件中,写下...
<?xml version="1.0" encoding="UTF-8" ?>
<acls>
<acl>
<name>SEC_E_All_Entities</name>
<objectName>HSII</objectName>
<objectType>SL_DIMENSION</objectType>
<accessMode>READWRITE</accessMode>
<flag>@IDESCENDANTS</flag>
<isUser>N</isUser>
</acl>
</acls>
在SEC_E_All_Americas.XML文件中,写下......
<?xml version="1.0" encoding="UTF-8" ?>
<acls>
<acl>
<name>SEC_E_ENT_Americas</name>
<objectName>Americas</objectName>
<objectType>SL_DIMENSION</objectType>
<accessMode>READ</accessMode>
<flag>MEMBER</flag>
<isUser>N</isUser>
</acl>
</acls>
此致 朱迪
答案 0 :(得分:0)
示例脚本
'Step 1 - Read the file and store the content in memory (an array)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\pankaj.jaju\Desktop\StackOverflow\acls.txt", 1)
arrFile = Split(objFile.ReadAll, vbCrLf) 'will store one line in each array index
objFile.Close
'Step 2 - Load the XML template in memory
Set xmlTemplate = CreateObject("MSXML2.DOMDocument.6.0")
With xmlTemplate
.ValidateOnParse = True
.Async = False
.LoadXML "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & _
"<acls>" & _
"<acl>" & _
"<name></name>" & _
"<objectName></objectName>" & _
"<objectType></objectType>" & _
"<accessMode></accessMode>" & _
"<flag></flag>" & _
"<isUser></isUser>" & _
"</acl>" & _
"</acls>"
End With
'Step 3 - Load the relevant fields for which the data is to be set from csv file
Set nodeFields = xmlTemplate.DocumentElement.SelectNodes("/acls/acl/*")
'Step 4 - Read each line of text and create XML
For i = LBound(arrFile) To UBound(arrFile)
arrLine = Split(arrFile(i), ",") 'will split the line into various fields (to be used to create the xml)
For j = LBound(arrLine) To UBound(arrLine) 'set values for each field
nodeFields(j).Text = arrLine(j)
Next
Set xmlNew = xmlTemplate
xmlNew.Save objFSO.BuildPath("C:\Users\pankaj.jaju\Desktop\StackOverflow\", nodeFields(0).Text & ".xml") 'copy modified template as new xml file
Set xmlNew = Nothing
Next