【问题标题】:Export excel data to json将excel数据导出为json
【发布时间】:2020-12-17 04:23:39
【问题描述】:

我在单元格“A2”和“B2”中有一个 3000-6000 行的 excel 工作簿是我需要导出为保存文件 FilenameA2B2.json 的文件名。在单元格“F2”“H2”中,行中的几个单元格是我需要插入到 for 中的数据

插入一个看起来像这样的脚本

{ "Auto" : { info, info,}{
Info: "F2"(from excel)
Media: "H2"(from excel) } 
more script

需要创建 6000 个唯一文件

【问题讨论】:

  • 欢迎来到 Stack Overflow!您提供的 JSON 示例看起来不像是有效的 JSON。您能否编辑您的答案以包含更多详细信息,并可能提及您迄今为止尝试过的内容?您更喜欢 VBA 中的解决方案,还是您有另一种偏好的语言?有很好的代码示例 in node.jspython 可以帮助您。

标签: json excel vba


【解决方案1】:

纯粹基于您在上面提供给我们的有限信息,我起草了以下内容,可能会对您有所帮助。

Sub createfiles()
    Dim r As Long, ff As Long, myFilename As String
    With ActiveSheet
    For r = 2 To 5 '(5 will do the first 4 rows. Alter this to your range, or detect range using normal methods)
        ff = FreeFile
        myFilename = .Cells(r, 1).Value & .Cells(r, 2).Value
        Open myFilename For Output As #ff
        Print #ff, filetext(.Cells(r, 6).Value, .Cells(r, 8).Value)
        Close ff
    Next
    End With
End Sub

Function filetext(info As String, media As String)
    filetext = "{""Auto"" : {info,info,}{ Info: """ & info & """, Media: """ & media & """} insert more script here}"
End Function

正如 Nick 指出的那样,如果您希望 json 阅读器稍后解析它,filetext 字符串可能需要整理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 2023-03-09
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    相关资源
    最近更新 更多