add markdown_from_table, markdown_whole_sheet, json_multirange

This commit is contained in:
Paul Trowbridge 2017-09-28 14:26:34 -04:00
parent 949c561a13
commit b0c229065a

View File

@ -2070,3 +2070,94 @@ Public Function MISCe_MaxLng(ByRef base As Long, ByRef compare As Long) As Long
End If
End Function
Public Function markdown_from_table(ByRef tbl() As Variant) As String
Dim msl() As Integer
Dim md As String
Dim r As Integer
Dim c As Integer
ReDim msl(UBound(tbl, 2))
'---determine max string length per column----
For c = 1 To UBound(tbl, 2)
For r = 1 To UBound(tbl, 1)
If Len(tbl(r, c)) > msl(c) Then msl(c) = Len(tbl(r, c))
Next r
Next c
'---build markdown table-----------
For r = 1 To UBound(tbl, 1)
If r = 2 Then
md = md & "|"
For c = 1 To UBound(tbl, 2)
md = md & "---" & String(msl(c) - 3, "-") & "|"
Next c
md = md & vbCrLf
End If
md = md & "|"
For c = 1 To UBound(tbl, 2)
md = md & tbl(r, c) & String(msl(c) - Len(tbl(r, c)), " ") & "|"
Next c
md = md & vbCrLf
Next r
markdown_from_table = md
End Function
Public Function json_multirange(ByRef r As range) As String
Dim ar As range
Dim r1() As Variant
Dim r2() As Variant
Dim rslt As String
Dim d() As String
Dim i As Integer
Dim dest As String
i = 1
For Each ar In r.Areas
r1 = ar
If i > 1 Then
rslt = rslt & "," & Me.json_from_table(r1, CStr(r1(1, 1)), True)
Else
rslt = Me.json_from_table(r1, CStr(r1(1, 1)), True)
End If
i = i + 1
Next ar
rslt = "{" & rslt & "}"
json_multirange = rslt
End Function
Function markdown_whole_sheet(ByRef sh As Worksheet) As String
Dim mr As Long
Dim mc As Long
Dim ir As Long
Dim ic As Long
Dim x As New TheBigOne
Dim tbl() As Variant
tbl = sh.range("A1:CZ1000")
For ic = 1 To UBound(tbl, 2)
For ir = 1 To UBound(tbl, 1)
If tbl(ir, ic) <> "" Then
mr = x.MISCe_MaxLng(ir, mr)
mc = x.MISCe_MaxLng(ic, mc)
End If
Next ir
Next ic
tbl = sh.range(sh.Cells(1, 1).Address & ":" & sh.Cells(mr, mc).Address)
markdown_whole_sheet = Me.markdown_from_table(tbl)
End Function