【发布时间】:2018-04-10 23:30:23
【问题描述】:
我在 Excel 中有一个必须从 JSON 源更新的大表。 在解析 JSON 后,数据以字典的形式被提取并提供给我。 我正在遍历数据中的所有字段并更新表中的相关列。
Public Function GetFields(ByVal sApiEndpoint As String, ByVal sSheetName As String, ByVal sTableName As String)
.........
'Parse the Json Response and Update Table
Dim dicParsed As Dictionary
With ActiveWorkbook.Sheets(sSheetName).ListObjects(sTableName)
Dim iCount As Integer
iCount = 1
Set dicParsed = JsonConverter.ParseJson(sRestResponse)
For Each Item In dicParsed("data")
iCount = iCount + 1
Next Item
If .ListRows.Count >= 1 Then
.DataBodyRange.Delete
End If
Set Rng = .Range.Resize(iCount, .HeaderRowRange.Columns.Count)
.Resize Rng
Dim iRow As Integer
iRow = 0
For Each Item In dicParsed("data")
On Error Resume Next
.DataBodyRange.Cells(iRow, .ListColumns("name").Index) = Item("name")
.DataBodyRange.Cells(iRow, .ListColumns("id").Index) = Item("id")
.DataBodyRange.Cells(iRow, .ListColumns("type").Index) = Item("schema")("type")
iRow = iRow + 1
Next Item
End With
.........
End Function
在关闭计算和更新的情况下,更新 500 行 15 列的表大约需要 5 分钟。
在这种情况下有没有更快的方法来更新数据?
【问题讨论】:
标签: vba performance excel