zoukankan      html  css  js  c++  java
  • access 2007 vba 开发中学到的知识(二)

    文件的导入和导出

    excel


    'excel导入
    Private Sub btnInExcel_Click()

    Dim strSelectFile As String
    With Application.FileDialog(3)
    .AllowMultiSelect = False
    .InitialFileName = ""
    .Filters.Clear
    .Filters.Add "EXCEL文件", "*.xls"
    If .Show = -1 Then
    strSelectFile = .SelectedItems.Item(1)
    Else
    Exit Sub
    End If
    End With
    DoCmd.TransferSpreadsheet 0, 8, "测试表", strSelectFile, True
    MsgBox "导入成功!"
    DoCmd.OpenTable "测试表"
    End Sub


    'excel导出
    Private Sub btnOutExcel_Click()

    Dim strSelectFile As String
    With Application.FileDialog(2)
    .AllowMultiSelect = False
    .InitialFileName = "test.xls"
    If .Show = -1 Then
    strSelectFile = .SelectedItems.Item(1)
    Else
    Exit Sub
    End If
    End With
    DoCmd.TransferSpreadsheet 1, 8, "测试表", strSelectFile, True
    MsgBox "导出成功!"
    ShellEx strSelectFile
    End Sub

    CSV

    '导入csv
    Private Sub btnInDOCMD_Click()
    Dim strSelectFile As String
    With Application.FileDialog(3)
    .AllowMultiSelect = False
    .InitialFileName = ""
    .Filters.Clear
    .Filters.Add "CSV文件", "*.CSV"
    If .Show = -1 Then
    strSelectFile = .SelectedItems.Item(1)
    Else
    Exit Sub
    End If
    End With
    DoCmd.TransferText acImportDelim, , "测试表", strSelectFile, True
    MsgBox "导入成功!"
    DoCmd.OpenTable "测试表"

    End Sub
    '导出csv
    Private Sub btnOutDOCMD_Click()
    Dim strSelectFile As String
    With Application.FileDialog(2)
    .AllowMultiSelect = False
    .InitialFileName = "test.csv"

    If .Show = -1 Then
    strSelectFile = .SelectedItems.Item(1)
    Else
    Exit Sub
    End If
    End With
    DoCmd.TransferText acExportDelim, , "测试表", strSelectFile, True
    MsgBox "导出成功!"
    ShellEx strSelectFile
    End Sub

    TXT


    '导出TXT
    Private Sub btnOutTXT_Click()

    Dim strSelectFile As String
    With Application.FileDialog(2)
    .AllowMultiSelect = False
    .InitialFileName = "test.txt"

    If .Show = -1 Then
    strSelectFile = .SelectedItems.Item(1)
    Else
    Exit Sub
    End If
    End With
    DoCmd.TransferText acExportDelim, , "测试表", strSelectFile, True
    MsgBox "导出成功!"
    ShellEx strSelectFile
    End Sub

    创建TXT并写入内容

    需要引用 Microsoft Script Runtime


    Dim fso As New FileSystemObject

    fso.CreateTextFile (CurrentProject.Path & " est.txt")
    fso.OpenTextFile(CurrentProject.Path & " est.txt", ForWriting).WriteLine "测试数据"

    在原有数据后面追加新数据

    fso.OpenTextFile(CurrentProject.Path & " est.txt", ForAppending).WriteLine "测试数据"

  • 相关阅读:
    024.Kubernetes掌握Pod-部署MongoDB
    023.Kubernetes掌握Pod-Pod扩容和缩容
    附010.Kubernetes永久存储之GlusterFS超融合部署
    附009.Kubernetes永久存储之GlusterFS独立部署
    022.Kubernetes掌握Pod-Pod升级和回滚
    021.Kubernetes掌握Pod-Pod调度策略
    020.Kubernetes掌握Pod-Pod基础使用
    018.Kubernetes二进制集群插件metrics-dashboard
    016.Kubernetes二进制集群插件coredns
    .NET Core 3.0之深入源码理解ObjectPool(二)
  • 原文地址:https://www.cnblogs.com/akatuki/p/4231582.html
Copyright © 2011-2022 走看看