VB6.0 读写excel表格/dat文件并保存
最近偶尔写了点VB - -
1.Excel读写
GlobalLists:
Dim xlsApp As Object
Dim xlsWB1 As Object
Dim xlsWS1 As Object
Form:
Private Sub writeDataToExcel()
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False ' 可视化
Set xlsWB1 = xlsApp.Workbooks.Open("F:\VB98\inputData\inputData1.xlsx") ' 修改为需要的文件路径-----------------------
Set xlsWS1 = xlsWB1.WorkSheets("Sheet1")
'写入(读取反过来即可)
xlsWS1.cells(excel_row + 5,excel_col + 5) = " (●.●)"
xlsApp.DisplayAlerts = False ' 不显示警告
xlsWB1.Close True '保存数据
xlsApp.quit
Set xlsApp = Nothing
Set xlsWB1 = Nothing
Set xlsWS1 = Nothing
End Sub
2.dat文件读写
Private Sub ReadDataFromDatFile()
Dim strBuff As String
Dim fileLength
Dim count As Integer
' 给出一个从.dat文件中读取前16个数字的例子,其中的数字按需修改--------------------------------------
' 如果需要写入数据,只需要file.write
count = 0
Open "F:\VB98\inputData\inputData2.dat" For Input As #1
Do Until EOF(1)
Input #1,num1
If count = 0 Then
ElseIf count <= 4 Then
Text1(count - 1).Text = num1
ElseIf count <= 8 Then
Text2(count - 5).Text = num1
ElseIf count <= 12 Then
Text3(count - 9).Text = num1
Else
Text4(count - 13).Text = num1
End If
' Print num1;
count = count + 1
Loop
Close #1
If ifOption1Click = 1 Then
res = record()
End If
End Sub
原文链接:https://www.f2er.com/vb/256683.html