Is it possible to output Yaml from Excel table using VBA?

Asked 2 years ago, Updated 2 years ago, 47 views

That's right.

I could find an article converting Excel tables to JSON, but I couldn't find any information converting them to Yaml.
If anyone knows, please let me know.

excel vba

2022-09-29 21:52

1 Answers

Since JSON is a subset of YAML, I would like to say that if JSON output is possible, YAML output is possible, but you want to output YAML-like(?) YAML.

Like JSON, YAML is just a string, so it's not impossible to output.You just need to combine strings.

A very simple example would be, for example:

Sub ToYAML()
    Dimr As Integer, c As Integer
    Dim result As String

    For = 2 To 6
        result=result&"-"
        Forc=1 To 3
            result=result&Cells(1,c).Value&":"&Cells(r,c).Value&vbCrLf&"
        Next c
        result=Left(result, Len(result)-2) 'Remove the excess " " at the end
    Next r

    Debug.Print result
End Sub

Enter a description of the image here

The range, whether it is Value or Text, the presence or absence of a quote, the output method, etc. are not mentioned in the question, so it is appropriate.Adjust as needed.


2022-09-29 21:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.