精华内容
下载资源
问答
  • 我用vb.net导出的PDF文件:代码如下 Public Sub ExcelToPdf(excelPath As String) Dim excel = New FileInfo(excelPath) If excel.Exists Then Dim dir = excel.DirectoryName Dim fileName = excel.Name....
  • 请高手指点,我在运行VB.NET时导出的XLS文件,为什么在EXCEL 2003打开是乱码,里面是乱七八糟的符号。而用EXCEL 2007打开就没问题请问这是怎么回事?代码如下,该怎么改才不会用EXCEL2003打开是乱码?
  • vb.net中怎么把datagrdview中的数据导出成excel文档 用的是ACCESS数据库 一下是我写的代码,发生了一些问题,请大神们看看,帮忙修改一下。 这是导出按钮的单击事件 ''要先添加引用才能使用下列语句Microsoft.Office...
  • 以下为我的代码 Private Sub ExcelExport_New(ByVal dt As DataTable, ByVal ProgressBar1 As Object) ProgressBar1.Visible = True ProgressBar1.Value = 10 '建立Excel Dim xlApp, xlBook, xlSheet As ...
  • 我初次写的时候,在MSDN上找过很多资料和代码,都很没有使用价值,后来借鉴了很多人的帖子,终于写出了这个程序,虽然代码很冗余,但是绝对能用,能让看了的人知道怎么处理这一系列过程。使用:首先要点清理数据库,...
  • 【e800编译】此示例演示如何使用ExportAsFixedFormat方法在Microsoft Excel 2010工作表中将数据以PDF...每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C#中(在Visual Studio 2...

    【e800编译】此示例演示如何使用ExportAsFixedFormat方法在Microsoft Excel 2010工作表中将数据以PDF或XPS格式导出。此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C#中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。Microsoft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。实例代码在Excel 2010中新建一工作簿,并将代码复制到Sheet1类模块。将光标置于TestExportAsFixedFormat内,按F8单步执行代码。SubTestExportAsFixedFormat()' For information on the final parameter, see this page:' /en-us/library/aa338206.aspxDimrngAsRangeSetrng=Range("A1:E10")SetupRangeDatarngDimfileNameAsString' Change this file name to meet your own needs:fileName="C:\Temp\Export.pdf"' Many of these properties are optional, and are included' here only to demonstrate how you might use them. The' Type parameter can be one of xlTypePDF and xlTypeXLS;' the Quality parameter can be one of xlQualityStandard and' xlQualityMinimum. Setting the OpenAfterPublish property' to True will fail if you don't have a default viewer' installed and configured.rng.ExportAsFixedFormatType:=xlTypePDF,_fileName:=fileName,Quality:=xlQualityStandard,_IncludeDocProperties:=True,IgnorePrintAreas:=True,_From:=1,To:=1,OpenAfterPublish:=TrueEndSubSubSetupRangeData(rngAsRange)rng.Formula="=RANDBETWEEN(1, 100)"EndSub

    展开全文
  • VB网络编程实例

    千次下载 热门讨论 2007-05-29 15:46:04
    ◆ 01.htm 1、怎么用mscomm控件检测modem是否与计算机联接正确?2、如何用mscomm挂断modem与别的电话机间的连接?(已接通) ◆ 02.htm CWinInetConnection---一个封装了WinInet API函数的类 ◆ 03....
  • SQL表的导入导出插入

    2008-10-29 16:39:00
    vb中把sql表导出成excel格式,请教怎么做?代码怎么写? 问题点数:100、回复次数:3Top 1 楼samying()回复于 2005-06-17 15:33:51 得分 20Dim strSource, strDestination As String Dim xlApp As New Excel.Ap

    在vb中把sql表导出成excel格式,请教怎么做?代码怎么写? 问题点数:100、回复次数:3Top

    src="/Include/Board.htm?Tags=" frameborder="0" scrolling="no">

    1 楼samying()回复于 2005-06-17 15:33:51 得分 20

    Dim   strSource,   strDestination   As   String  
                      Dim   xlApp   As   New   Excel.Application  
                      Dim   xlBook   As   New   Excel.Workbook  
                      Dim   xlSheet   As   New   Excel.Worksheet  
                     
                      strSource   =   App.Path   &   "/collectTemplate.xls"  
                      strDestination   =   "C:/PrintView.xls"  
                     
                      Set   fs   =   CreateObject("Scripting.FileSystemObject")  
                      If   fs.FileExists(strDestination)   Then  
                            fs.DeleteFile   strDestination  
                      End   If  
                       
                      FileCopy   strSource,   strDestination   '将模版文件拷贝到一个临时文件  
                       
                       
                       
                      Set   xlBook   =   xlApp.Workbooks.Open(strDestination)  
                      Set   xlSheet   =   xlBook.Worksheets(1)  
                       
                      xlSheet.Cells(1,   1).Value   =   "项目建设计划表"  
                      xlSheet.Cells(1,   1).Font.Size   =   20  
                      xlSheet.Cells(1,   1).Font.Bold   =   True  
                      xlSheet.Cells(1,   1).VerticalAlignment   =   xlVAlignCenter  
                      xlSheet.Cells(1,   1).HorizontalAlignment   =   xlHAlignCenter  
                       
                      xlSheet.Range("A5").CopyFromRecordset   rs     //rs是记录集  
                      Dim   str   As   String  
                      str   =   "U"   &   CStr(4   +   rs.RecordCount)  
                      xlSheet.Range("A5:"   &   str).Borders.LineStyle   =   xlContinuous  
                      xlSheet.Range("A5:"   &   str).WrapText   =   True  
                      xlSheet.Range("A5:"   &   str).Font.Size   =   9  
                      xlSheet.Range("A5:"   &   str).VerticalAlignment   =   xlVAlignCenter  
                      xlSheet.Range("A5:"   &   str).HorizontalAlignment   =   xlHAlignCenter  
                      xlApp.Visible   =   True  
                      xlSheet.Activate  
                   
                      xlBook.Save  
                      SendKeys   "%(F)",   True  
                      SendKeys   "V",   True  
                      Unload   frmPrintViewWait  
                      mdiFrm.sbrMain.Panels(1).Text   =   "就绪"  
                      Set   xlSheet   =   Nothing  
                      Set   xlBook   =   Nothing  
                      Set   xlApp   =   NothingTop

    2 楼flyingZFX(卍 南无阿弥陀佛 卍)回复于 2005-06-17 15:34:07 得分 80

    SQL   SERVER   和EXCEL的数据导入导出  
       
       
       
      1、在SQL   SERVER里查询Excel数据:  
       
      --   ======================================================  
       
      SELECT   *    
       
      FROM   OpenDataSource(   'Microsoft.Jet.OLEDB.4.0',  
       
      'Data   Source="c:/book1.xls";User   ID=Admin;Password=;Extended   properties=Excel   5.0')...[Sheet1$]  
       
       
       
      下面是个查询的示例,它通过用于   Jet   的   OLE   DB   提供程序查询   Excel   电子表格。  
       
      SELECT   *    
      FROM   OpenDataSource   (   'Microsoft.Jet.OLEDB.4.0',  
      'Data   Source="c:/Finance/account.xls";User   ID=Admin;Password=;Extended   properties=Excel   5.0')...xactions  
      -------------------------------------------------------------------------------------------------  
       
       
       
      2、将Excel的数据导入SQL   server   :  
       
      --   ======================================================  
       
      SELECT   *   into   newtable  
       
      FROM   OpenDataSource(   'Microsoft.Jet.OLEDB.4.0',  
       
      'Data   Source="c:/book1.xls";User   ID=Admin;Password=;Extended   properties=Excel   5.0')...[Sheet1$]  
       
       
       
      实例:  
       
      SELECT   *   into   newtable  
       
      FROM   OpenDataSource(   'Microsoft.Jet.OLEDB.4.0',  
       
      'Data   Source="c:/Finance/account.xls";User   ID=Admin;Password=;Extended   properties=Excel   5.0')...xactions  
       
      -------------------------------------------------------------------------------------------------  
       
       
       
      3、将SQL   SERVER中查询到的数据导成一个Excel文件  
       
      --   ======================================================  
       
      T-SQL代码:  
       
      EXEC   master..xp_cmdshell   'bcp   库名.dbo.表名out   c:/Temp.xls   -c   -q   -S"servername"   -U"sa"   -P""'  
       
      参数:S   是SQL服务器名;U是用户;P是密码  
       
      说明:还可以导出文本文件等多种格式  
       
       
       
      实例:EXEC   master..xp_cmdshell   'bcp   saletesttmp.dbo.CusAccount   out   c:/temp1.xls   -c   -q   -S"pmserver"   -U"sa"   -P"sa"'  
       
       
       
      EXEC   master..xp_cmdshell   'bcp   "SELECT   au_fname,   au_lname   FROM   pubs..authors   ORDER   BY   au_lname"   queryout   C:/   authors.xls   -c   -Sservername   -Usa   -Ppassword'  
       
       
       
      在VB6中应用ADO导出EXCEL文件代码:    
       
      Dim   cn   As   New   ADODB.Connection  
       
      cn.open   "Driver={SQL   Server};Server=WEBSVR;DataBase=WebMis;UID=sa;WD=123;"  
       
      cn.execute   "master..xp_cmdshell   'bcp   "SELECT   col1,   col2   FROM   库名.dbo.表名"   queryout   E:/DT.xls   -c   -Sservername   -Usa   -Ppassword'"  
       
      -------------------------------------------------------------------------------------------------  
       
       
       
      4、在SQL   SERVER里往Excel插入数据:  
       
      --   ======================================================  
       
      insert   into   OpenDataSource(   'Microsoft.Jet.OLEDB.4.0',  
       
      'Data   Source="c:/Temp.xls";User   ID=Admin;Password=;Extended   properties=Excel   5.0')...table1   (A1,A2,A3)   values   (1,2,3)  
       
       
       
      T-SQL代码:  
       
      INSERT   INTO    
       
      OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',    
       
      'Extended   Properties=Excel   8.0;Data   source=C:/training/inventur.xls')...[Filiale1$]    
       
      (bestand,   produkt)   VALUES   (20,   'Test')    
       
      -------------------------------------------------------------------------------------------------  
       
      总结:利用以上语句,我们可以方便地将SQL   SERVER、ACCESS和EXCEL电子表格软件中的数据进行转换,为我们提供了极大方便!  

    展开全文
  • VB操作EXCEL技巧

    热门讨论 2008-03-05 11:24:40
    快速将数据从MSFLEXGRID控件导出到EXCEL(保证比那些一格一格写数据的要快的多), 快速将数据从EXCEL导入到MSFLEXGRID控件(同上) 如何通过剪贴板将数据在程序和EXCEL中相互粘贴(这下用户可以直接和EXCEL互动了) 如何...
  • PE导出/输入表演示

    千次阅读 2007-12-29 08:44:00
    本程序代码演示怎么遍历导出/输入表.下面是完整源码.frmMain.fmVERSION 5.00Begin VB.Form frmMain BorderStyle = 1 Fixed Single Caption = "PE导出/输入表演示" ClientHeight = 5655 ClientLeft = 45

    本程序代码演示怎么遍历导出/输入表.下面是完整源码.

    frmMain.fm

    VERSION 5.00
    Begin VB.Form frmMain
       BorderStyle     =   1  'Fixed Single
       Caption         =   "PE导出/输入表演示"
       ClientHeight    =   5655
       ClientLeft      =   45
       ClientTop       =   435
       ClientWidth     =   7890
       LinkTopic       =   "Form1"
       LockControls    =   -1  'True
       MaxButton       =   0   'False
       MinButton       =   0   'False
       ScaleHeight     =   5655
       ScaleWidth      =   7890
       StartUpPosition =   2  '屏幕中心
       Begin VB.CommandButton cmdPath
          Caption         =   "..."
          Height          =   315
          Left            =   6960
          TabIndex        =   1
          Top             =   80
          Width           =   885
       End
       Begin VB.TextBox txtPath
          Height          =   285
          Left            =   0
          TabIndex        =   0
          Top             =   90
          Width           =   6915
       End
       Begin VB.CommandButton cmdExit
          Cancel          =   -1  'True
          Caption         =   "退出(&C)"
          Height          =   375
          Left            =   6660
          TabIndex        =   6
          Top             =   5160
          Width           =   1185
       End
       Begin VB.CommandButton cmdImport
          Caption         =   "输入表(&I)"
          Height          =   375
          Left            =   5460
          TabIndex        =   5
          Top             =   5160
          Width           =   1185
       End
       Begin VB.CommandButton cmdExport
          Caption         =   "导出表(&E)"
          Height          =   375
          Left            =   4260
          TabIndex        =   4
          Top             =   5160
          Width           =   1185
       End
       Begin VB.ListBox lstImport
          Height          =   4560
          Left            =   3960
          TabIndex        =   3
          Top             =   450
          Width           =   3915
       End
       Begin VB.ListBox lstExport
          Height          =   4560
          Left            =   0
          TabIndex        =   2
          Top             =   450
          Width           =   3915
       End
    End
    Attribute VB_Name = "frmMain"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit
    Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

    Private Function IsArraryInitialize(strArray() As String) As Boolean
        On Error GoTo ErrHandle
        Dim i As Long
        i = UBound(strArray)
        IsArraryInitialize = True
        Exit Function
    ErrHandle:
        IsArraryInitialize = False
    End Function

    Private Function IsObjArraryInitialize(objArray() As ImportDetailInfo) As Boolean
        On Error GoTo ErrHandle
        Dim i As Long
        i = UBound(objArray)
        IsObjArraryInitialize = True
        Exit Function
    ErrHandle:
        IsObjArraryInitialize = False
    End Function

    Private Sub cmdExit_Click()
        Unload Me
    End Sub

    Private Sub cmdExport_Click()
        Dim pExportInfo As ExportInfo, i As Integer
        If Trim(txtPath.Text) = "" Then
            MsgBox "请输入文件路径!!", vbCritical, "提示"
            txtPath.SetFocus
            Exit Sub
        End If
        If Dir(txtPath.Text, 1 Or 2 Or 4) = "" Then
            MsgBox "目标文件不存在!!", vbCritical, "提示"
            txtPath.SetFocus
            Exit Sub
        End If
        lstExport.Clear
        If GetExportTable(txtPath.Text, pExportInfo) Then
            lstExport.AddItem pExportInfo.strDllName & "导出函数列表:"
            If IsArraryInitialize(pExportInfo.strFuns) Then
                For i = 0 To UBound(pExportInfo.strFuns)
                    lstExport.AddItem "     " & pExportInfo.strFuns(i)
                Next
            End If
        End If
    End Sub

    Private Sub cmdImport_Click()
        Dim pImportInfo As ImportInfo, i As Integer, j As Integer
        If Trim(txtPath.Text) = "" Then
            MsgBox "请输入文件路径!!", vbCritical, "提示"
            txtPath.SetFocus
            Exit Sub
        End If
        If Dir(txtPath.Text, 1 Or 2 Or 4) = "" Then
            MsgBox "目标文件不存在!!", vbCritical, "提示"
            Exit Sub
        End If
        lstImport.Clear
        If GetImportTable(txtPath.Text, pImportInfo) Then
            lstImport.AddItem pImportInfo.strExePath & "输入函数列表:"
            If IsObjArraryInitialize(pImportInfo.pDetailInfo) Then
                For i = 0 To UBound(pImportInfo.pDetailInfo)
                    lstImport.AddItem "     模块:" & pImportInfo.pDetailInfo(i).strDllName & ""
                    If IsArraryInitialize(pImportInfo.pDetailInfo(i).strFuns) Then
                        For j = 0 To UBound(pImportInfo.pDetailInfo(i).strFuns)
                            lstImport.AddItem "          " & pImportInfo.pDetailInfo(i).strFuns(j)
                        Next
                    End If
                Next
            End If
        End If
    End Sub

    Private Sub cmdPath_Click()
        txtPath.Text = ShowDialogFile(Me.hWnd, 1, "请选择文件", "", "文件 (*.*)" & Chr(0) & "*.*", "", "")
    End Sub

    Private Sub Form_Initialize()
        InitCommonControls
    End Sub

    modPEInfo.bas

    Attribute VB_Name = "modPEInfo"

    Option Explicit
    Private Declare Function MapAndLoad Lib "imagehlp.dll" (ByVal ImageName As String, ByVal DllPath As String, LoadedImage As LOADED_IMAGE, ByVal DotDll As Boolean, ByVal ReadOnly As Boolean) As Long
    Private Declare Function UnMapAndLoad Lib "imagehlp.dll" (hBase As Any) As Long
    Private Declare Function ImageRvaToVa Lib "dbghelp" (ByRef NtHeaders As Any, Base As Any, ByVal Rva As Long, ByRef LastRvaSection As Any) As Long
    Private Declare Function CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" (ByVal hFile As Long, lpFileMappigAttributes As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
    Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
    Private Declare Function UnmapViewOfFile Lib "kernel32" (lpBaseAddress As Any) As Long

    Private Type LOADED_IMAGE      '48个字节
       ModuleName As Long
       hFile As Long
       MappedAddress As Long      '映射文件基址
       pFileHeader As Long         'IMAGE_PE_FILE_HEADER的指针
       pLastRvaSection As Long      '第一个COFF段文件头的指针   ??
       NumberOfSections As Long
       pSections As Long         '第一个COFF段文件头的指针
       Characteristics As Long      '映像特征值
       fSystemImage As Byte
       fDosImage As Byte
       Links(7) As Byte         '2个长整型
       SizeOfImage As Long
    End Type

    Private Const FILE_MAP_READ = 4
    Private Const PAGE_READONLY = &H2
    Private Enum ImageSignatureTypes
       IMAGE_DOS_SIGNATURE = &H5A4D     ''// MZ
       IMAGE_OS2_SIGNATURE = &H454E     ''// NE
       IMAGE_OS2_SIGNATURE_LE = &H454C  ''// LE
       IMAGE_VXD_SIGNATURE = &H454C     ''// LE
       IMAGE_NT_SIGNATURE = &H4550      ''// PE00
    End Enum

    Private Type IMAGE_DOS_HEADER
        Magic    As Integer
        cblp     As Integer
        cp       As Integer
        crlc     As Integer
        cparhdr  As Integer
        minalloc As Integer
        maxalloc As Integer
        ss       As Integer
        sp       As Integer
        csum     As Integer
        ip       As Integer
        cs       As Integer
        lfarlc   As Integer
        ovno     As Integer
        res(3)   As Integer
        oemid    As Integer
        oeminfo  As Integer
        res2(9)  As Integer
        lfanew      As Long
    End Type

    Private Type IMAGE_FILE_HEADER
        Machine              As Integer
        NumberOfSections     As Integer
        TimeDateStamp        As Long
        PointerToSymbolTable As Long
        NumberOfSymbols      As Long
        SizeOfOtionalHeader  As Integer
        Characteristics      As Integer  '标志Dll
    End Type

    Private Type IMAGE_DATA_DIRECTORY
        DataRVA     As Long
        DataSize    As Long
    End Type

    Private Type IMAGE_OPTIONAL_HEADER
        Magic             As Integer
        MajorLinkVer      As Byte
        MinorLinkVer      As Byte
        CodeSize          As Long
        InitDataSize      As Long
        unInitDataSize    As Long
        EntryPoint        As Long
        CodeBase          As Long
        DataBase          As Long
        ImageBase         As Long
        SectionAlignment  As Long
        FileAlignment     As Long
        MajorOSVer        As Integer
        MinorOSVer        As Integer
        MajorImageVer     As Integer
        MinorImageVer     As Integer
        MajorSSVer        As Integer
        MinorSSVer        As Integer
        Win32Ver          As Long
        ImageSize         As Long
        HeaderSize        As Long
        Checksum          As Long
        Subsystem         As Integer
        DLLChars          As Integer
        StackRes          As Long
        StackCommit       As Long
        HeapReserve       As Long
        HeapCommit        As Long
        LoaderFlags       As Long
        RVAsAndSizes      As Long
        DataEntries(15)   As IMAGE_DATA_DIRECTORY
    End Type

    Private Type IMAGE_NT_HEADERS
        Signature As Long
        FileHeader As IMAGE_FILE_HEADER
        OptionalHeader As IMAGE_OPTIONAL_HEADER
    End Type

    Private Type IMAGE_SECTION_HEADER
        SectionName(7)    As Byte
        Address           As Long
        VirtualAddress    As Long
        SizeOfData        As Long
        PData             As Long
        PReloc            As Long
        PLineNums         As Long
        RelocCount        As Integer
        LineCount         As Integer
        Characteristics   As Long
    End Type

    Private Type IMAGE_IMPORT_DESCRIPTOR
        Characteristics As Long
        TimeDateStamp As Long
        ForwarderChain As Long
        pName As Long
        FirstThunk As Long
    End Type

    Private Type IMAGE_EXPORT_DIRECTORY
        Characteristics As Long
        TimeDateStamp As Long
        MajorVersion As Integer
        MinorVersion As Integer
        pName As Long
        Base As Long
        NumberOfFunctions As Long
        NumberOfNames As Long
        AddressOfFunctions As Long
        AddressOfNames As Long
        AddressOfNameOrdinals As Long
    End Type

    Private Type IMAGE_IMPORT_BY_NAME
        Hint As Integer
        pName(259) As Byte
    '    pName As Integer
    End Type

    Private Type IMAGE_THUNK_DATA32
        AddressOfData As Long 'IMAGE_IMPORT_BY_NAME
    End Type

    Private Type IMAGE_THUNK_DATA
        AddressOfData As IMAGE_IMPORT_BY_NAME
    End Type

    'typedef struct _IMAGE_IMPORT_DESCRIPTOR {
    '    union {
    '        DWORD   Characteristics;            // 0 for terminating null import descriptor
    '        DWORD   OriginalFirstThunk;         // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
    '    };
    '    DWORD   TimeDateStamp;                  // 0 if not bound,
    '                                            // -1 if bound, and real date/time stamp
    '                                            //     in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
    '                                            // O.W. date/time stamp of DLL bound to (Old BIND)
    '
    '    DWORD   ForwarderChain;                 // -1 if no forwarders
    '    DWORD   Name;
    '    DWORD   FirstThunk;                     // RVA to IAT (if bound this IAT has actual addresses)
    '} IMAGE_IMPORT_DESCRIPTOR;
    'typedef IMAGE_IMPORT_DESCRIPTOR UNALIGNED *PIMAGE_IMPORT_DESCRIPTOR;

    'typedef struct _IMAGE_EXPORT_DIRECTORY {
    '    DWORD   Characteristics;
    '    DWORD   TimeDateStamp;
    '    WORD    MajorVersion;
    '    WORD    MinorVersion;
    '    DWORD   Name;
    '    DWORD   Base;
    '    DWORD   NumberOfFunctions;
    '    DWORD   NumberOfNames;
    '    DWORD   AddressOfFunctions;     // RVA from base of image
    '    DWORD   AddressOfNames;         // RVA from base of image
    '    DWORD   AddressOfNameOrdinals;  // RVA from base of image
    '} IMAGE_EXPORT_DIRECTORY, *PIMAGE_EXPORT_DIRECTORY;

    'typedef struct _IMAGE_IMPORT_BY_NAME {
    '    WORD    Hint;
    '    BYTE    Name[1];
    '} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;

    'typedef struct _IMAGE_THUNK_DATA32 {
    '    union {
    '        PBYTE  ForwarderString;
    '        PDWORD Function;
    '        DWORD Ordinal;
    '        PIMAGE_IMPORT_BY_NAME  AddressOfData;
    '    } u1;
    '} IMAGE_THUNK_DATA32;
    'typedef IMAGE_THUNK_DATA32 * PIMAGE_THUNK_DATA32;

    'Private Type IMAGE_RESOURCE_DIR
    '    Characteristics   As Long
    '    TimeStamp         As Long
    '    MajorVersion      As Integer
    '    MinorVersion      As Integer
    '    NamedEntries      As Integer
    '    IDEntries         As Integer
    'End Type
    '
    'Private Type RESOURCE_DIR_ENTRY
    '    Name              As Long
    '    offset            As Long
    'End Type
    '
    'Private Type RESOURCE_DATA_ENTRY
    '    offset            As Long
    '    Size              As Long
    '    CodePage          As Long
    '    Reserved          As Long
    'End Type
    '
    'Private Type IconDescriptor
    '    ID       As Long
    '    offset   As Long
    '    Size     As Long
    'End Type

    Public Type ExportInfo
        strDllName As String
        strFuns() As String
    End Type

    Public Type ImportDetailInfo
        strDllName As String
        strFuns() As String
    End Type

    Public Type ImportInfo
        strExePath As String
        pDetailInfo() As ImportDetailInfo
    End Type

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    Private Const FILE_SHARE_READ = &H1
    '***************************************************************************************************************************************************
    '用于读写文件函数
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function ReadFile Lib "kernel32" (ByVal lngFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
    'Private Declare Function WriteFile Lib "kernel32" (ByVal lngFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
    Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Private Declare Function SetFilePointer Lib "kernel32" (ByVal lngFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
    Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
    '***************************************************************************************************************************************************
    Public gpExportTable As ExportInfo

    Public Function GetImportTable(ByVal strFilePath As String, pImportInfo As ImportInfo) As Boolean
        Dim tNTHeader      As IMAGE_NT_HEADERS
        Dim lngTmp As Long, strTmp As String, lngNextAddr As Long
        Dim i As Integer, intCount As Integer, intFunCount As Integer
        Dim pImport As IMAGE_IMPORT_DESCRIPTOR
        Dim pTunk As IMAGE_THUNK_DATA32, lngTunk As Long, lngNextTunk As Long
        Dim bytBuffer(129) As Byte
        Dim pDosHear As IMAGE_DOS_HEADER
        Dim pLoadModule As LOADED_IMAGE
        Dim pName As IMAGE_IMPORT_BY_NAME
        pImportInfo.strExePath = strFilePath
        If MapAndLoad(strFilePath, vbNullString, pLoadModule, True, True) Then
            CopyMemory pDosHear, ByVal pLoadModule.MappedAddress, Len(pDosHear)
            CopyMemory tNTHeader, ByVal pLoadModule.pFileHeader, Len(tNTHeader)
            lngTmp = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, tNTHeader.OptionalHeader.DataEntries(1).DataRVA, ByVal 0&)
            lngNextAddr = lngTmp
            Do While lngTmp <> 0
                CopyMemory pImport, ByVal lngNextAddr, Len(pImport)
                lngNextAddr = lngNextAddr + Len(pImport)
                lngTmp = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pImport.pName, ByVal 0&)
                If lngTmp = 0 Then Exit Do
                CopyMemory bytBuffer(0), ByVal lngTmp, 130
                strTmp = StrConv(bytBuffer, vbUnicode)
                strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
                Debug.Print "DLL模块为:" & strTmp
                ReDim Preserve pImportInfo.pDetailInfo(intCount)
                pImportInfo.pDetailInfo(intCount).strDllName = strTmp
                If pImport.Characteristics <> 0 Then
                    lngTunk = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pImport.Characteristics, ByVal 0&)
                Else
                    lngTunk = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pImport.FirstThunk, ByVal 0&)
                End If
                If lngTunk <> 0 Then
                    lngNextTunk = lngTunk
                    intFunCount = 0
                    Do While lngTunk <> 0
                        CopyMemory pTunk, ByVal lngNextTunk, Len(pTunk)
                        lngNextTunk = lngNextTunk + 4
                        lngTunk = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pTunk.AddressOfData, ByVal 0&)
                        If lngTunk = 0 Then Exit Do
                        CopyMemory pName, ByVal lngTunk, Len(pName)
                        strTmp = StrConv(pName.pName, vbUnicode)
                        strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
                        Debug.Print "       ----函数为:" & strTmp
                        ReDim Preserve pImportInfo.pDetailInfo(intCount).strFuns(intFunCount)
                        pImportInfo.pDetailInfo(intCount).strFuns(intFunCount) = strTmp
                        intFunCount = intFunCount + 1
                    Loop
                End If
                intCount = intCount + 1
            Loop
            UnMapAndLoad pLoadModule
            GetImportTable = True
            Exit Function
        End If
       
    End Function

    Public Function GetExportTable(ByVal strFilePath As String, pExportInfo As ExportInfo) As Boolean
        Dim tNTHeader      As IMAGE_NT_HEADERS
        Dim lngTmp As Long, strTmp As String, lngNextAddr As Long
        Dim i As Integer, intNo As Integer
        Dim pExport As IMAGE_EXPORT_DIRECTORY
        Dim hAddr As Long, lngNextTunk As Long
        Dim bytBuffer(129) As Byte
        Dim pLoadModule As LOADED_IMAGE
        Dim pName As IMAGE_IMPORT_BY_NAME
        If MapAndLoad(strFilePath, vbNullString, pLoadModule, True, True) Then
            CopyMemory tNTHeader, ByVal pLoadModule.pFileHeader, Len(tNTHeader)
            If tNTHeader.OptionalHeader.DataEntries(0).DataRVA = 0 Then
                MsgBox "没有发现到出表结构!!", vbCritical, "提示"
                Exit Function
            End If
            lngTmp = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, tNTHeader.OptionalHeader.DataEntries(0).DataRVA, ByVal 0&)
            CopyMemory pExport, ByVal lngTmp, Len(pExport)
            lngTmp = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pExport.pName, ByVal 0&)
            CopyMemory bytBuffer(0), ByVal lngTmp, 130
            strTmp = StrConv(bytBuffer, vbUnicode)
            strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
            Debug.Print "DLL模块为:" & strTmp
            pExportInfo.strDllName = strTmp
            ReDim pExportInfo.strFuns(pExport.NumberOfFunctions - 1)
            For i = 0 To pExport.NumberOfFunctions - 1
                '获取函数对应偏移地址指针
                hAddr = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, pExport.AddressOfNames + i * 4, ByVal 0&)
                '获取函数对应偏移地址
                CopyMemory hAddr, ByVal hAddr, 4
                '获取函数对应RAV地址
                hAddr = ImageRvaToVa(ByVal pLoadModule.pFileHeader, ByVal pLoadModule.MappedAddress, hAddr, ByVal 0&)
                CopyMemory bytBuffer(0), ByVal hAddr, 130
                strTmp = StrConv(bytBuffer, vbUnicode)
                strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
                Debug.Print "       ----函数名称为:" & strTmp
                pExportInfo.strFuns(i) = strTmp
            Next
            GetExportTable = True
            UnMapAndLoad pLoadModule
        End If
    End Function

    Public Function GetImportInfo(ByVal strFilePath As String) As Boolean
        Dim lngFile As Long
        Dim pNTHeader      As IMAGE_NT_HEADERS
        Dim lngTmp As Long, strTmp As String, lngNextAddr As Long
        Dim i As Integer, j As Integer
        Dim pImport As IMAGE_IMPORT_DESCRIPTOR, pExport As IMAGE_EXPORT_DIRECTORY
        Dim pTunk As IMAGE_THUNK_DATA32, lngTunk As Long, lngNextTunk As Long
        Dim bytBuffer(129) As Byte
        Dim pDosHear As IMAGE_DOS_HEADER
        Dim pLoadModule As LOADED_IMAGE
        Dim pName As IMAGE_IMPORT_BY_NAME
        Dim hMap As Long, hBase As Long, hAddr As Long
        lngFile = CreateFile(ByVal strFilePath, ByVal &H80000000, FILE_SHARE_READ, ByVal 0&, ByVal 3, ByVal 0&, ByVal 0&)
        If (lngFile > 0) Then
            hMap = CreateFileMapping(lngFile, ByVal 0&, PAGE_READONLY, 0, 0, vbNullString)
            If hMap = 0 Then
                Exit Function
            End If
            hBase = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)
            If hBase = 0 Then
                Exit Function
            End If
            CopyMemory pDosHear, ByVal hBase, Len(pDosHear)
            If pDosHear.Magic <> &H5A4D Then
                Exit Function
            End If
            CopyMemory pNTHeader, ByVal hBase + pDosHear.lfanew, Len(pNTHeader)
            If pNTHeader.Signature <> IMAGE_NT_SIGNATURE Then
                Exit Function
            End If
            Do While 1
                hAddr = ImageRvaToVa(ByVal hBase + pDosHear.lfanew, ByVal hBase, pNTHeader.OptionalHeader.DataEntries(1).DataRVA + j * Len(pImport), ByVal 0&)
                CopyMemory pImport, ByVal hAddr, Len(pImport)
                If pImport.pName = 0 Or pImport.Characteristics = 0 Then
                    Exit Do
                End If
                hAddr = ImageRvaToVa(ByVal hBase + pDosHear.lfanew, ByVal hBase, pImport.pName, ByVal 0&)
                CopyMemory bytBuffer(0), ByVal hAddr, 130
                strTmp = StrConv(bytBuffer, vbUnicode)
                strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
                Debug.Print "DLL模块为:" & strTmp
                i = 0
                Do While 1
                    hAddr = ImageRvaToVa(ByVal hBase + pDosHear.lfanew, ByVal hBase, pImport.Characteristics + i * 4, ByVal 0&)
                    If hAddr = 0 Then Exit Do
                    CopyMemory pTunk, ByVal hAddr, Len(pTunk)
                    hAddr = ImageRvaToVa(ByVal hBase + pDosHear.lfanew, ByVal hBase, pTunk.AddressOfData, ByVal 0&)
                    If hAddr = 0 Then Exit Do
                    CopyMemory pName, ByVal hAddr, Len(pName)
                    strTmp = StrConv(pName.pName, vbUnicode)
                    strTmp = Left(strTmp, InStr(strTmp, Chr(0)) - 1)
                    Debug.Print "       ----函数为:" & strTmp
                    i = i + 1
                Loop
                j = j + 1
            Loop
        End If
        UnmapViewOfFile ByVal hBase
        CloseHandle hMap
        CloseHandle lngFile
        GetImportInfo = True
    End Function


     


     modBrowse.bas

    Attribute VB_Name = "modBrowse"
    Option Explicit
    Private Const BIF_RETURNONLYFSDIRS = 1

    Private Const BIF_DONTGOBELOWDOMAIN = 2

    Private Const OFN_HIDEREADONLY = &H4

    Private Const OFN_PATHMUSTEXIST = &H800

    Private Const OFN_FILEMUSTEXIST = &H1000

    Private Const OFN_OVERWRITEPROMPT = &H2

    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long

    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long

    Private Type BrowseInfo
        hWndOwner As Long
        pIDLRoot As Long
        pszDisplayName As Long
        lpszTitle As Long
        ulFlags  As Long
        lpfnCallback   As Long
        lParam   As Long
        iImage   As Long
    End Type

    Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

    Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

    Private Type OPENFILENAME
        lStructSize As Long
        hWnd As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As String
        nMaxCustFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        Flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As Long
        lpfnHook As Long
        lpTemplateName As String
    End Type

    Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long

    Public Function GetFolderPath(ByVal objControl As TextBox, ByVal hWndOwner As Long)
        Dim lpIDList As Long
        Dim sBuffer As String
        Dim szTitle As String
        Dim tBrowseInfo As BrowseInfo

        szTitle = "请选择源路径:"
        With tBrowseInfo
            .hWndOwner = hWndOwner
            .lpszTitle = lstrcat(szTitle, "")
            .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
        End With

        lpIDList = SHBrowseForFolder(tBrowseInfo)

        If (lpIDList) Then
            sBuffer = Space(256)
            SHGetPathFromIDList lpIDList, sBuffer
            sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
            objControl.Text = sBuffer
        End If
    End Function

    Public Function ShowDialogFile(hWnd As Long, wMode As Integer, szDialogTitle As String, szFilename As String, szFilter As String, szDefDir As String, szDefExt As String) As String
        Dim x As Long, OFN As OPENFILENAME, szFile As String, szFileTitle As String
       
        OFN.lStructSize = Len(OFN)
        OFN.hWnd = hWnd
        OFN.lpstrTitle = szDialogTitle
        OFN.lpstrFile = szFilename & String$(250 - Len(szFilename), 0)
        OFN.nMaxFile = 255
        OFN.lpstrFileTitle = String$(255, 0)
        OFN.nMaxFileTitle = 255
        OFN.lpstrFilter = szFilter
        OFN.nFilterIndex = 1
        OFN.lpstrInitialDir = szDefDir
        OFN.lpstrDefExt = szDefExt

        If wMode = 1 Then
            OFN.Flags = OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
            x = GetOpenFileName(OFN)
        Else
            OFN.Flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST
            x = GetSaveFileName(OFN)
        End If
       
        If x <> 0 Then
            If InStr(OFN.lpstrFile, Chr$(0)) > 0 Then
                szFile = Left$(OFN.lpstrFile, InStr(OFN.lpstrFile, Chr$(0)) - 1)
            End If
            ShowDialogFile = szFile
        Else
            ShowDialogFile = ""
        End If
       
    End Function


    展开全文
  • 我从以下的链接,找到可以导出datagridview成txt档的代码 但是有一个问题,就是表头会不见,请问这个代码可以怎么修改呢 以下的程式已测试过,可用 ... Next
  • 最大上限是65536行数据,但我用了2007,2013都一个结果,又有人说把后缀改成“.xlsx”但是这样导出的数据用excel2007和2013都打不开,能用WPS2016打开,数据显示还是6万多,到底怎么弄啊大神们?导数据代码如下图!...
  • 在敲机房的时候涉及到导出为Excel的一段代码,先要引用一下Microsoft Excel 15.0 Object Library这个控件,但是我的电脑上打开,工程→引用之后没有这个控件!!!!我明明装了Windows Office办公套装的啊?怀疑我与世界...
    在敲机房的时候涉及到导出为Excel的一段代码,先要引用一下Microsoft Excel 15.0 Object Library这个控件,但是我的电脑上打开,工程→引用之后没有这个控件!!!!我明明装了Windows Office办公套装的啊?怀疑我与世界脱轨?怎么也是新世纪的人,怎么可能不装office呢?
          如果你也遇到类似的问题,那么请按照下面的方法解决:

          1.打开工程→引用

                                       

          2.单机浏览

                                         

    3.找到Windows office的安装路径(主要是Excel的安装路径),然后选择文件类型"*.exe,*.dll",找到"excel.exe",打开

         

    你就会发现神奇的一幕出现了,你的引用里面有Microsoft Excel 15.0 Object Library这个控件了!!!

                                                                        

    展开全文
  • 转贴自 http://www.vcsoft.org/bbs/dispbbs.asp?boardid=16&id=123背景: 在VB下可以把一个工程编译成DLL导出在别的VB工程中使用,那么VC怎么能轻松地把自己所需要的部分导出呢?需求: 1, 现有一已完工的VC6...
  • 昨晚本来就很累,好烦,结果搞到三更半夜始终搞不定:用VC6调用C#导出的类库始终没法创建对象,用VB也一样。重新审查接口定义,自觉挺规范的,怎么搞的?重新翻看框架设计指南,忽然发现下面这句话:如果没有公共...
  • 既然说到了C#,那么一奶同胞的VB.Net怎么能忽略呢? Visual Basic .Net和C#的内核完全一样,都是.Net,只是外在的语言形式不一样。这种情况下,调用CChart的方法也非常类似。 总的说来,就是采用C风格代码,并把...
  • vc++ 应用源码包_2

    2012-09-15 14:27:40
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 应用源码包_1

    2012-09-15 14:22:12
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 应用源码包_6

    2012-09-15 14:59:46
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 应用源码包_5

    2012-09-15 14:45:16
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 应用源码包_4

    2012-09-15 14:38:35
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 应用源码包_3

    2012-09-15 14:33:15
    Excel文件的导入和导出操作 主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件查询系统,...
  • vc++ 开发实例源码包

    2014-12-16 11:25:17
    Excel文件的导入和导出操作 如题。主要的实现在CMyExcel类中。 expclass_src dll库的演示。 fge.1.1.alpha.sdk 精灵系统,一套MFC渲染引擎,含2D/3D等渲染,效果看源码,IFEngine是整个引擎接口,IFSystem是硬件...
  • DLL函数查看器V3.5

    热门讨论 2013-07-24 10:10:37
    * 新增对函数的易语言和VB的函数及结构声明 * 新增查壳功能 * 新增查看PE文件头信息 * 美化窗口界面等 感谢使用山寨版DLL函数查看器,遇到问题请发送邮件 infopet@qq.com 因为以前使用 DLL函数查看器2.0 遇到很多...
  • arcgis工具

    2012-10-22 22:37:31
    应用工具CALCULATE AREA 或者使用VBA代码实现 新建字段并开启Advanced 写入代码,面积计算: Dim Output as double Dim pArea as Iarea Set pArea = [shape] 在最后的一个空格里面写入代码(即:字段名)pArea...
  • asp.net知识库

    2015-06-18 08:45:45
    实现C#和VB.net之间的相互转换 深入剖析ASP.NET组件设计]一书第三章关于ASP.NET运行原理讲述的补白 asp.net 运行机制初探(httpModule加载) 利用反射来查看对象中的私有变量 关于反射中创建类型实例的两种方法 ASP...
  • AspJpeg 2.4.0.1

    2012-06-20 15:08:42
    学过vb或者.net的同志肯定一看就明白了。刷子来着。呵呵。 一、图片缩略 Set Jpeg = Server.CreateObject("Persits.Jpeg") 调用组件 Path = Server.MapPath("images") & "\clock.jpg" 待处理图片路径 Jpeg....

空空如也

空空如也

1 2
收藏数 27
精华内容 10
关键字:

vb怎么导出代码