简体   繁体   中英

Export excel data to json

I have a excel workbook 3000-6000 lines in cell "A2"&"B2" is the file name that i need to export as saved file FilenameA2B2.json. In cell "F2" "H2" and few cells in the row is data I need to insert into a for

Insert into a script that looks like

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

Need to create 6000 unique files

Based purely on the limited information you've given us above, I've drafted up the following which might help you along the way.

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

As Nick pointed out though, the filetext string might want tidying up if you're expecting a json reader to parse this later on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM