Json datei in Excel schön exportieren?

4 Antworten

'Hier ein Makro welches 'meine' JSON files nach Excel holt
Public Sub main()
   Const ForReading As Long = 1
   Dim fso          As Object    'Scripting.FileSystemObject
   Dim sf           As Object    'Scripting.File
   Dim sts          As Object    'Scripting.TextStream
   Dim strDateipfad As String
   Dim strZeile     As String
   Dim iCnt, iRet   As Integer
   Dim bShow        As Boolean
   Dim tempStr
   
   strDateipfad = "C:\temp\My.json"

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set sf = fso.GetFile(strDateipfad)
   Set sts = sf.OpenAsTextStream(ForReading)
   iCnt = 3
   bShow = False
   ThisWorkbook.Worksheets("Test").Range("A3:B200000").ClearContents
   Application.ScreenUpdating = False
   Application.EnableEvents = False
   Do
      strZeile = sts.ReadLine
      sPos = InStr(1, strZeile, "[Rule")
      If sPos > 0 Then
        ePos = InStr(sPos, strZeile, "]")
        tempStr = Mid(strZeile, sPos + 1, ePos - sPos - 1)
        tempStr = Strings.Replace(tempStr, "-", " ", 1, -1, vbTextCompare)
        ThisWorkbook.Worksheets("Test").Cells(iCnt, 1).Value = Strings.Replace(tempStr, "_", "-", 1, -1, vbTextCompare)
        
        strZeile = sts.ReadLine
        tempStr = Strings.Split(strZeile, Chr(34), -1, vbTextCompare)
        ThisWorkbook.Worksheets("Test").Cells(iCnt, 2).Value = tempStr(UBound(tempStr) - 1)
        
        iCnt = iCnt + 1
      End If
      DoEvents
   Loop Until sts.AtEndOfStream
   Application.ScreenUpdating = True
   Application.EnableEvents = True
MsgBox "Done !! #: " & (iCnt - 1), vbInformation
End Sub

In Excel gibt es im Menü Daten die Funktion "Text in Spalten" dort kannst du die Kategorien in die einzelnen Spalten verteilen. In deinem Fall kannst du : und , als Trennzeichen verwenden, oder was eben für dich sinnvoll ist.

Excel ist ein Tabellenkalkulationsprogramm (deine Daten vom Screenshot sehen nicht danach aus, das du da etwas berechnen möchtest) und kein Datenverwaltungstool. Also erst schauen welche Software für den Zweck geeignet ist. Vielleicht ein Datenanalysetool?

Ich würde nach dem Doppelpunkt trennen und den Rest in eine neue Spalte schieben. Ggfs. die Anführungszeichen am Anfang und am Ende entfernen für bessere Lesbarkeit.