diff --git a/TheBigOne.cls b/TheBigOne.cls index ca53c84..3031a58 100644 --- a/TheBigOne.cls +++ b/TheBigOne.cls @@ -2069,4 +2069,95 @@ Public Function MISCe_MaxLng(ByRef base As Long, ByRef compare As Long) As Long Exit Function End If -End Function \ No newline at end of file +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