VB6.0 读写excel表格/dat文件并保存

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

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...