我有一个程序可以运行一堆不同类型的测试。每个测试都有许多可以设置的不同设置。我正在尝试将用于每个测试的设置导出到 Excel 文件。现在写,我将所有设置都存储在 Dictionary(Of String, Object) 中,因为设置的值可以是不同的类型,即(Double、Integer、String、Boolean)。我正在尝试像这样重铸字典中的值,但 DirectCast 不喜欢 t,它说类型 t 未定义。我也试过 CType 但它似乎不起作用。设置的类型是 Dictionary(Of String, Object)
Private Sub writeTestSettings(ByRef book As HSSFWorkbook, ByVal settings As Dictionary(Of String, Object))
Dim settingsSheet As HSSFSheet = book.CreateSheet("Test Configuration")
Dim i As Integer = 0
For Each key In settings.Keys
Dim row = settingsSheet.CreateRow(i)
Dim cell1 As HSSFCell = row.CreateCell(0)
cell1.SetCellValue(key)
Dim cell2 As HSSFCell = row.CreateCell(1)
Dim value As Object = settings(key)
Dim t As Type = value.GetType()
cell2.SetCellValue(DirectCast(value, t))
Next
End Sub