»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > VBÎĵµ > Êý¾Ý±¨±í
ÓÃEXCEL2000×÷ΪVBµÄ×ÊÔ´Îļþ±¨±í
·¢±íÈÕÆÚ£º2003-06-23 00:00:00×÷Õߣº¶ ³ö´¦£º  

  Ðí¶àÅóÓÑ°ÑEXCEL×÷Ϊ±¨±íµÄ¹¤¾ß£¬°ÑÊý¾ÝдÈëEXCEL²¢²»À§ÄÑ£¬µ«´æÔÚһЩÎÊÌ⣬È磺¿Í»§

ÐÞ¸ÄÁ˱¨±íµÄ¸ñʽ£¬»òÕß°ÑÉè¼ÆºÃµÄ±¨±íÎļþɾ³ýÁË£¬ÈçºÎ½â¾öÕâЩÎÊÌâÄØ£¿ËѱéÁ˹úÄÚÍâµÄÕ¾

µã£¬Òàδ·¢ÏÖÓÐʲôºÃµÄ°ì·¨¡£

  ÓеÄÅóÓѸøEXCELÎļþ¼ÓÃÜÂ룬ÕâÖÖ°ì·¨Ö»·ÀÖ¹ÁË¿Í»§Ð޸ı¨±í¸ñʽ£¬Èç¹û¿Í»§Òƶ¯»òɾ³ýÁË

Õâ¸ö±¨±íÎļþ£¬ÈÔÈ»»á³öÎÊÌâ¡£ÏÖÔÚÎÒÃÇÀ´ÊÖ¾øµÄ£º°ÑÉè¼ÆºÃµÄ¿Õ°×±¨±í¼Óµ½×ÊÔ´ÎļþÀïÃ棬ÿ´Î

±¨±íµÄʱºòÏÈ°Ñ×ÊÔ´ÎļþÀïÃæµÄEXCEL±¨±íдµ½µ±Ç°Ä¿Â¼Ï£¬È»ºóÓɳÌÐòÌîдÊý¾Ý£¬»òÏÔʾ»ò´ò

Ó¡£¡

  ¿ªÊ¼°É£¡ÏÈ×öһЩ׼±¸¹¤×÷£¬ÔÚÕâÀï¼ÙÉèÒÑ×¼±¸ÁËÒÔ϶«¶«£º

ÔÚµ±Ç°Ä¿Â¼ÏÂÓÐÒ»access2000Êý¾Ý¿âdb1.mdb£¬´ò¿ªÃÜÂëÊÇ7281322£¬ÄÚÓÐÒ»ÕűíMonRep´æ·Å×Å

Òª±¨±íµÄÊý¾Ý£»Éè¼ÆºÃµÄ¿Õ°×EXCEL2000±¨±írp.xls£¬´ò¿ªÃÜÂëÒ²ÊÇ7281322¡£

´ò¿ªVB£¬Ð½¨Ò»¸ö¹¤³Ì£¬ÔÚ"¹¤³Ì"¡ú"ÒýÓÃ"ÀïÃæÑ¡È¡Microsoft ActiveX Data Object 2.1 

LibraryºÍMicrosoft Excel 9.0 Object Library£»

ÔÚ"Íâ½Ó³ÌÐò"¡ú"Íâ½Ó³ÌÐò¹ÜÀíÆ÷"ÀïÃæ¼ÓÔØ"VB 6 ×ÊÔ´±à¼­Æ÷"£¬ÔÚ"¹¤³Ì×ÊÔ´¹ÜÀíÆ÷"ÀïÃæµã»÷Êó

±êÓÒ¼ü£¬Ñ¡È¡"Ìí¼Ó×ÊÔ´Îļþ"£¬Ëæ±ã¸ø×ÊÔ´ÎļþÆð¸öÃû×Ö£¬³öÏÖ"VB×ÊÔ´±à¼­Æ÷"ºó£¬µã"Ìí¼Ó×Ô¶¨

Òå×ÊÔ´"°´Å¥£¬Ñ¡È¡ÄãÉè¼ÆºÃµÄ±¨±írp.xls£¬µã»÷"±£´æ"°´Å¥£¬×¢Ò⣺ÕâÀïʹÓÃÁËĬÈϵÄÀà

ÐÍ"CUSTOM"ºÍĬÈϵıêʶºÅ101£¬Êµ¼ÊÓ¦ÓÃÖÐÄã¿É×öÐ޸ġ£

°´ÏÂCtrl-t£¬Ñ¡È¡Microsoft DataGrid Control 6.0(OLEDB)ÔÚĬÈÏ´°ÌåForm1ÉÏ»­Ò»¸ö

DataGrid£¬Ä¬ÈÏÃû³ÆDataGrid1¡£

ÔÚ´°ÌåÀïÌí¼ÓÈçÏ´úÂ룺

Private Sub Form_Load()

  Dim rst As Recordset

  Set Cnn1 = New ADODB.Connection

  CnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path 

& "\db1.mdb" _

& ";Mode=Read|Write;Persist Security Info=False;Jet OLEDB:Database 

Password=7281322"

Cnn1.Open CnnStr

  Sql = "SELECT * FROM MonRep"

  Set rst = New ADODB.Recordset

  rst.CursorLocation = adUseClient

  rst.Open Sql, Cnn1, adOpenKeyset, adLockOptimistic, adCmdText

 Set DataGrid1.DataSource = rst

End Sub

Private Sub Form_Resize()

DataGrid1.Width = 0.95 * Me.Width

DataGrid1.Height = 0.75 * Me.Height

End Sub

ÔÚ´°ÌåµÄ"ͨÓÃ"ÀïÃæÌí¼ÓÒÔÏ´úÂ룺£¨×¢ÒâAPIº¯ÊýµÄÉùÃ÷Ò»¶¨ÒªÐ´ÔÚÒ»ÐÐÀ

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal 

hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal 

lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, 

lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As 

Long, ByVal 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, 

ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal 

dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As 

Long

Const WM_CLOSE = &H10

Const GENERIC_WRITE = &H40000000

Const CREATE_ALWAYS = 2

Const FILE_ATTRIBUTE_NORMAL = &H80

Public Sub CopyExcel()

  Dim hNewFile As Long, bBytes() As Byte

  Dim nSize As Long

  Dim hwnd

  hwnd = FindWindow("XLMAIN", "Microsoft Excel - rp.xls")

  If hwnd <> 0 Then

    SendMessage hwnd, WM_CLOSE, 0, 0'Èç¹û¿Í»§Ã»Óйرոñ¨±í£¬ÌáʾËû¹Ø±ÕËü

    Exit Sub

  End If

  If Dir(App.Path & "\rp.xls") = "rp.xls" Then

  Kill App.Path & "\rp.xls"

  End If

  bBytes = LoadResData(101, "CUSTOM")

  hNewFile = CreateFile(App.Path & "\rp.xls", GENERIC_WRITE, 0, 0, 

CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)

nSize = UBound(bBytes) - LBound(bBytes) + 1

  WriteFile hNewFile, bBytes(0), nSize, nSize, ByVal 0&

  CloseHandle hNewFile

End Sub

  ÔÚ´°ÌåÉÏ»­Ò»°´Å¥£¬Ìí¼ÓÒÔÏ´úÂ룺

Private Sub Command1_Click()

Me.MousePointer = 11

CopyExcel

  Dim ex As Object

  Dim i As Integer

  Dim j As Integer

  Dim XlApp As Excel.Application

  Dim xlBook As Excel.Workbook

  Dim xlSheet As Excel.Worksheet

  Set XlApp = CreateObject("Excel.Application")

  XlApp.Visible = True

  Set xlBook = XlApp.Workbooks.Open(App.Path & "\rp.xls", , , , 7281322)

  Set xlSheet = xlBook.Worksheets(1)

  Dim rst As Recordset

  Set Cnn1 = New ADODB.Connection

  CnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path 

& "\db1.mdb" _

  & ";Mode=Read|Write;Persist Security Info=False;Jet OLEDB:Database 

Password=7281322"

  Cnn1.Open CnnStr

  Sql = "SELECT * FROM MonRep"

  Set rst = New ADODB.Recordset

  rst.CursorLocation = adUseClient

  rst.Open Sql, Cnn1, adOpenKeyset, adLockOptimistic, adCmdText

  rst.MoveFirst

  For j = 0 To rst.RecordCount - 1

  For i = 3 To rst.Fields.Count

  xlSheet.Cells(i + 2, j + 3) = rst.Fields(i - 1).Value

  Next i

  rst.MoveNext

  Next j

  For i = 3 To rst.Fields.Count

  zzz = 0

  For j = 0 To rst.RecordCount - 1

  zzz = zzz + xlSheet.Cells(i + 2, j + 3)

  Next j

   xlSheet.Cells(i + 2, 16) = zzz

  Next i

  xlSheet.Cells(3, 15) = Date

' ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

' xlBook.Close

' XlApp.Quit

Me.MousePointer = 0

End Sub

  Èç¹ûÄã²»ÏëÏÔʾ¶øÊÇÏëÖ±½Ó´òÓ¡±¨±í£¬¿ÉÒÔ°ÑXlApp.Visible = TrueÈ¥µô£¬¶øÆôÓÃ×îºó¼Ó×¢

Ê͵ÄÈýÐÐÃüÁî¡£

¸ã¶¨ÁË£¡°´ÏÂF5ÔËÐкóµã»÷°´Å¥£¬Äã»á¿´µ½Éú³ÉµÄ±¨±í¡£ÀûÓÃÕâÖÖ·½·¨£¬ÄãÔÙÒ²²»Óõ£ÐÄ¿Í»§ÆÆ»µ

ÄãµÄ±¨±íÁË£¬Ë¬Âð£¿Èç¹ûÄãÀÁµÃ×Ô¼º×öÒ»±é£¬µ½µÚÒ»VBÂÛ̳http://www.vbgood.comÈ¥ÏÂÔØÎÒµÄʾ

ÀýÔ´´úÂë¿´¿´°É¡£¸ÃʾÀý´úÂëÔÚÒÔÏ»·¾³ÏÂͨ¹ý£º

    Win98+VB6SP3+Excl2000+Access2000

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00174