是否可以在VBA中将Excel表转换为json [英] Is it possible in VBA convert Excel table to json
问题描述
我需要将大约20列和很多行的excel表中的数据转换为json.我在vba中找不到用于此目的的简短代码示例.我发现了一个 https://github.com/VBA-tools /VBA-JSON/blob/master/JsonConverter.bas ,但是它非常大.也许这是一个简短的例子?
I need convert data from excel table with about twenty columns and a lot of rows into json. I don't found a short example of code for this purpose in vba. I found this one https://github.com/VBA-tools/VBA-JSON/blob/master/JsonConverter.bas , but it is very large. May be it is a shorter example?
推荐答案
我将使用此版本的修改版本: http://www.excelvbamacros.in/2015/01 /export-range-in-jason-format.html
I'd go with modified version of this one: http://www.excelvbamacros.in/2015/01/export-range-in-jason-format.html
如果要将其写入文件,则有一个代码:
if you want to write it to file there's a code:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\some_dir\mydata.json", True, True)
Fileout.Write jsonStringFromConvertFunction
Fileout.Close
这篇关于是否可以在VBA中将Excel表转换为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!