Original Excel Format
The VBA Code
Sub ExcelToJson() Dim n_row, n_col, r, c, I As Integer Dim wse, wsj As Worksheet Set wse = ActiveWorkbook.Sheets("Excel") Set wsj = ActiveWorkbook.Sheets("JSON") n_row = wse.UsedRange.Rows.Count n_col = wse.UsedRange.Columns.Count I = 0 For r = 2 To n_row I = I + 1 wsj.Cells(I, 1) = "{" For c = 1 To n_col I = I + 1 If IsNumeric(wse.Cells(r, c)) Then wsj.Cells(I, 1) = wse.Cells(1, c) & ":" & wse.Cells(r, c) & "," Else wsj.Cells(I, 1) = wse.Cells(1, c) & ":'" & wse.Cells(r, c) & "'," End If Next I = I + 1 wsj.Cells(I, 1) = "}," Next MsgBox "Finished" End Sub |
The Output
0 Comments