加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 07:34:02 所属栏目:百科 来源:网络整理
导读: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.Vis

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:VB98inputDatainputData1.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:VB98inputDatainputData2.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读