excel 格式:(省略)
=========================================================
程序:
Dim SRC_HEAD As String
Dim SRC_TAIL As String
Sub createSource()
' 选择的sheet
Sheets("Sheet1").Select
HEAD
TAIL
' xm的位置
Dim srcFile As String
srcFile = ActiveWorkbook.Path & "\" & "AAA.xml"
' 开始行
GYO = 3
' 内容
Dim content As String
content = ""
Do While True
If (Cells(GYO, 7).Value = "") Then
Exit Do
Else
content = content & " <cp-mapping>" + vbCrLf
content = content & " <cp-code>" & Cells(GYO, 7).Value & "</cp-code>" & vbCrLf
content = content & " <controller-class operation-code=""300"">jp.co.jip.trb.client.ju." _
& Cells(GYO, 17).Value & "." _
& Cells(GYO, 18).Value & "." _
& Cells(GYO, 19).Value & "." _
& "JU0S6" & Cells(GYO, 7).Value & "1McoFacade</controller-class>" & vbCrLf
content = content & " <display-class>jp.co.jip.trb.client.ju." _
& Cells(GYO, 17).Value & "." _
& Cells(GYO, 18).Value & "." _
& Cells(GYO, 19).Value & "." _
& "JU0S6" & Cells(GYO, 7).Value & "1McoFacade.INIT_FROM_JU0S610200</display-class>" & vbCrLf
content = content & " </cp-mapping>" & vbCrLf & vbCrLf
End If
GYO = GYO + 1
Loop
createSourceFile srcFile, SRC_HEAD & content & SRC_TAIL
MsgBox "Ceate Message OK !"
End Sub
=====================================================================================================
Sub createSourceFile(fileName, fileContent)
On Error GoTo ERR_CREATE
Open fileName For Output As #1
Print #1, fileContent
Close #1
Exit Sub
ERR_CREATE:
MsgBox "错误:" & Error(Err.Number) & "(文件:" & fileName & "发现不到)"
End Sub
Function HEAD()
SRC_HEAD = ""
SRC_HEAD = SRC_HEAD & "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <nxml>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <mode>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <real-mode>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <operation-code>100</operation-code>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <operation-code>110</operation-code>" & vbCrLf
SRC_HEAD = SRC_HEAD & " <operation-code>120</operation-code>" & vbCrLf
SRC_HEAD = SRC_HEAD & " </real-mode>" & vbCrLf
SRC_HEAD = SRC_HEAD & " </mode>" & vbCrLf
End Function
Function TAIL()
SRC_TAIL = ""
SRC_TAIL = SRC_TAIL & " </nxml>" & vbCrLf
End Function
// ====================生成的xml结构如下==========================================================================
<?xml version="1.0" encoding="UTF-8"?>
<nxml>
<mode>
<real-mode>
<operation-code>100</operation-code>
<operation-code>110</operation-code>
<operation-code>120</operation-code>
</real-mode>
</mode>
<cp-mapping>
<cp-code>A010</cp-code>
<controller-class operation-code="300">jp.co.jip.trb.client.ju.checkpoint.model.a010jutaku.JU0S6A0101McoFacade</controller-class>
<display-class>jp.co.jip.trb.client.ju.checkpoint.model.a010jutaku.JU0S6A0101McoFacade.INIT_FROM_JU0S610200</display-class>
</cp-mapping>
<cp-mapping>
<cp-code>A020</cp-code>
<controller-class operation-code="300">jp.co.jip.trb.client.ju.checkpoint.model.a020mutan.JU0S6A0201McoFacade</controller-class>
<display-class>jp.co.jip.trb.client.ju.checkpoint.model.a020mutan.JU0S6A0201McoFacade.INIT_FROM_JU0S610200</display-class>
</cp-mapping>
。。。。。。。。。。
</nxml>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1534245