我在VBA中使用以下特定格式将数组写入CSV文件(部分原因是为了在正常保存时将aorund excel放入&#34;&#34;在每个单元格周围)。< / p>
我现在正试图转移到VB.net。 我看过aorund并试过各种迭代的选项无济于事。
Sub WriteCSV(varHoldingsArray, strTempLocation)
Dim i, j As Integer
Dim strCompiled As String
Open strTempLocation For Output As #1
For i = LBound(varHoldingsArray, 2) To UBound(varHoldingsArray, 2)
For j = LBound(varHoldingsArray, 1) To UBound(varHoldingsArray, 1)
Select Case j
Case Is > LBound(varHoldingsArray, 2)
strCompiled = strCompiled & varHoldingsArray(j, i)
Case LBound(varHoldingsArray, 2)
strCompiled = strCompiled & "," & varHoldingsArray(j, i)
End Select
Next j
If i <> UBound(varHoldingsArray, 2) Then
strCompiled = strCompiled & vbNewLine
End If
Next i
Print #1, strCompiled
Close #1
End Sub
我的问题是打开文件打印。
我换了:
Open strTempLocation For Output As #1
使用:
File.Create(strTempLocation) For Output As #1
虽然&#34; For Output&#34;在VBA中使用的部分似乎没有预料到(这是我迷路的地方)。我在项目中引用了System和System.IO。
然后我在最后的.net等价物之后:
Print #1, strCompiled
Close #1