誰も本当に答えがないようです。あなたたちを責められない。
完全に新しいXMLファイルを作成するマクロを作成することによって、この問題を解決しました。誰かが気にするなら、ここにコードがあります。私は通常、VBAで動作しないので、おそらくスーパーエレガントではありません。
Sub Text()
Dim arrHeader() As String, Max As Integer, Col As Integer, arrContent() As String, Row As Integer
Dim filesys, testfile, XTab As String
STab = " "
Max = 1
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile = filesys.CreateTextFile("C:\Users\edvpr\Desktop\test.xml", True)
testfile.WriteLine "<?xml version=""1.0"" encoding=""UTF-8""?>"
testfile.WriteLine "<ottopartner xmlns=""http://www.ottogroupb2b.com/ottopartner"">"
Do
Max = Max + 1
Loop Until Cells(1, Max) = ""
Col = 1
ReDim arrHeader(1 To Max - 1) As String
Do
arrHeader(Col) = Cells(1, Col)
Col = Col + 1
Loop Until Col = Max
Row = 2
ReDim arrContent(1 To Max - 1) As String
Do
Col = 1
If Row = 2 Then
Do
arrContent(Col) = Cells(Row, Col)
If arrContent(Col) <> "" And arrHeader(Col) = "LKZ" Then
testfile.WriteLine "<" + Trim(arrHeader(Col)) + ">" + Trim(arrContent(Col)) + "</" + Trim(arrHeader(Col)) + ">"
testfile.WriteLine "<Styles>"
End If
Col = Col + 1
Loop Until Col = Max
End If
Col = 1
Do
arrContent(Col) = Cells(Row, Col)
If Trim(arrContent(Col)) <> "" And Trim(arrHeader(Col)) <> "LKZ" Then
If Trim(arrHeader(Col)) = "OrderQuantityDefault" Then
XTab = STab + STab
testfile.WriteLine XTab + "<Item>"
End If
If Trim(arrHeader(Col)) = "InvoicingStartDate" Then
XTab = STab + STab + STab
testfile.WriteLine XTab + "<SKU>"
End If
If Trim(arrHeader(Col)) = "StyleNo" Then
If Row > 2 Then
testfile.WriteLine XTab + "</SKU>"
XTab = STab + STab
testfile.WriteLine XTab + "</Item>"
XTab = STab
testfile.WriteLine XTab + "</Style>"
End If
XTab = STab
testfile.WriteLine XTab + "<Style>"
End If
testfile.WriteLine XTab + STab + "<" + Trim(arrHeader(Col)) + ">" + Trim(arrContent(Col)) + "</" + Trim(arrHeader(Col)) + ">"
End If
Col = Col + 1
Loop Until Col = Max
Row = Row + 1
Loop Until Cells(Row, 1) = ""
testfile.WriteLine "</SKU>"
testfile.WriteLine "</Item>"
testfile.WriteLine "</Style>"
testfile.WriteLine "</Styles>"
testfile.WriteLine "</ottopartner>"
testfile.Close
End Sub
マクロは、左から右に向かってタグを作成し、残りのデータを上から下に塗りつぶします。また、OCDのためにXMLをインデントします。