【发布时间】:2019-06-23 17:21:48
【问题描述】:
我使用 VBA 创建了一个 CSV 到 Json 转换器。为此,我创建了以下函数:
If parseAsArrays Then ' Check to see if we need to make our JSON an array; if not, we'll make it an object
For rowCounter = 1 To rangeToParse.Rows.Count ' Loop through each row
temp = "" ' Reset temp's value
For columnCounter = 1 To rangeToParse.Columns.Count ' Loop through each column
temp = temp & """" & rangeToParse.Cells(rowCounter, columnCounter) & """" & ","
Next
temp = "[" & Left(temp, Len(temp) - 1) & "]," ' Remove extra comma from after last object
parsedData = parsedData & temp ' Add temp to the data we've already parsed
Next
我的“parsedData”子在这里:
Sub parseData()
Worksheets("Sheet2").Range("b1") = toJSON(getValuesRange("Sheet1"), False) ' Set cell B1's value to our JSON data
结束子
代码运行良好,但有时生成的 json 对于一个单元格来说太大了。因此,如果 json 对于一个单元格来说太大,我想创建一个 if 子句来将 json 写入两个或多个单元格中。有人知道怎么做吗?
【问题讨论】: