excel通过宏来导出json数据

来源:互联网 发布:双面劳伦斯知乎 编辑:程序博客网 时间:2024/06/08 16:15
Sub 导出JSON()    Dim s As String    Dim FullName As String, rng As Range    Dim row As Integer, column As Integer, maxrow As Integer    Dim strContent As String    Application.ScreenUpdating = False        FullName = (ThisWorkbook.Path & "/" & Cells(1, 2) & ".txt") ' Cells(1, 2) 表示第1行,第二列的内容    '配置区域    proline = 5 '程序名定义行    begindatalen = 6 '数据起始行    row = ActiveSheet.UsedRange.Rows.Count '最大行    column = ActiveSheet.UsedRange.Columns.Count '最大列    strContent = "{" & """" & Cells(1, 2) & """" & ":["  'json组成部分    For m = begindatalen To row        If Cells(m, 1) <> "" Then                        strContent = strContent & "{"                        For n = 1 To column                If n = column Then                    strContent = strContent & """" & Cells(proline, n) & """" & ":" & """" & Cells(m, n) & """"                Else                    strContent = strContent & """" & Cells(proline, n) & """" & ":" & """" & Cells(m, n) & """" & ","                End If            Next n                        If m = row Then                                strContent = strContent & "}"                            Else                                strContent = strContent & "},"                            End If                    End If    Next m        strContent = strContent & "]}"    WriteUTF8File strContent, FullName, False    Application.ScreenUpdating = True    MsgBox "数据已导出"End Sub


PS:在excel中插入一个宏安钮,然后编辑该宏代码即可。

0 0
原创粉丝点击