ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð±Ð¦³ÃöADODB.STREAM©MMicrosoft.XMLHTTPªº¥Îªk

½Ð±Ð¦³ÃöADODB.STREAM©MMicrosoft.XMLHTTPªº¥Îªk

§Ú¥´ºâ±NYAHOO FINANCE´£¨ÑªºCSVÀɮפU¸ü§@¤ÀªR¡A©ó¬O¦bºô¤W§ä¨ì¤F²V¦X¥ÎADODB.STREAM©MMicrosoft.XMLHTTP¨Ó¤U¸üªº¤èªk¡A¦ý§Úµo²{¸ê®Æ¹ê¦b¤Ó¦h¡A®Ú¥»¤£¯à¤è«K¨Ï¥Î¡C
©Ò¥H¥´ºâ§â¸ê®Æ¶×¤JACCESS§@¾ã²z¡A¨Ã®Ú¾Úºô¤Wªº±Ð¾Ç¼g¤F¤U­±ªºCODE¡G
  1. Sub GetPrice()
  2. Dim wks As Workspace
  3. Dim dbs As Database
  4. Dim rs As DAO.Recordset
  5. Dim mySQL As String, myUrl As String
  6. Dim WinHttpReq As Object

  7. Set wks = DBEngine.Workspaces(0)
  8. Set dbs = wks.OpenDatabase("D:\Shares\temp.mdb")

  9. shareNo = Format(1, "0000")

  10. myUrl = "http://ichart.finance.yahoo.com/table.csv?s=" & shareNo & ".HK&a=09&b=27&c=2001&d=07&e=29&f=2012&g=d&ignore=.csv"

  11. T1 = "D:\Shares\temp01\" & shareNo & ".csv"

  12. Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
  13. WinHttpReq.Open "GET", myUrl, False
  14. WinHttpReq.Send

  15. If WinHttpReq.Status = 200 Then
  16.     Set oStream = CreateObject("ADODB.Stream")
  17.     oStream.Open
  18.     oStream.Type = 1
  19.     oStream.Write WinHttpReq.ResponseBody
  20.     oStream.SaveToFile T1
  21.     oStream.Close
  22. End If


  23. Set r1 = Workbooks.Open(T1)
  24. Set r2 = r1.Sheets(1).Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious)

  25. If Not r2 Is Nothing Then
  26.     r = r2.Row
  27.    
  28.     mySQL = "insert into Price select * from (select " & shareNo & " as Share, Date, Open, High, Low, Close, Volume as Vol, [Adj Close] as AClose from [Excel 8.0;hdr=yes;imex=1;Database=" & T1 & "].[" & shareNo & "$A1:G" & r & "])"

  29.     dbs.Execute (mySQL)

  30.     r1.Close
  31.     Kill T1
  32. End If


  33. End Sub
½Æ»s¥N½X
¦ý³o¬qCODE¦³¨Ç°ÝÃD¡A§Æ±æ¦U¦ì¥i¥H¦h¥[«ü±Ð¡G
1) §Ú¤£¤Ó©ú¥ÕADODB.STREAM©MMicrosoft.XMLHTTP¨º³¡¥÷ªº·N«ä¡Aºô¤W©M§Ú¤â¤Wªº°Ñ¦Ò®Ñ³£¨S¦³´£¤Î¡A¹ê¦b¤£¤F¸Ñ·í¤¤ªº¹B§@
2) §Ú³o¬qCODEªº¬yµ{À³¸Ó¬O¤U¸ü¨º­ÓCSV¡A¸g¹LMicrosoft.XMLHTTPŪ¨ú¸ê®Æ¡A¦A¥ÎADODB.STREAM¼g¦¨¤@­ÓCSV¡AµM«á§ÚŪ¨úCSVªº¸ê®Æ¡A¥[¤WSHARENO¡AIMPORT¨ìACCESS¡A³Ì«á§âCSV§R±¼¡C
½Ð°Ý·í¤¤
Ū¨ú¸ê®Æ>Àx¦s¦¨CSV>Ū¨úCSV>¼g¤JACCESS>§R°£CSVªº¹Lµ{
¯à§_§ï¦¨¡A
Ū¨ú¸ê®Æ>>¼g¤JACCESS?
ÁÂÁ¦U¦ì

¦^´_  ¤p«L«È
¸Õ¸Õ¬Ý
GBKEE µoªí©ó 2012-8-30 16:21



    §Ú­è­è¸Õ¤ñ¸û¥Î.ADDNEW©M.UPDATE©MSQL INSERT ³t«×¤ñ¸û¡A§Úµo²{¥ÎSQL INSERT¤ñ«eªÌ§Ö«Ü¦h
  1. Set wb = Workbooks.Open(myUrl)
  2.         With myRS
  3.             For Each a In ActiveSheet.Range([A2], [A2].End(xlDown))
  4.                 .AddNew        '²K¥[¦U­ÓÄæ¦ìªº¸ê®Æ
  5.                 For i = 1 To .Fields.Count - 1
  6.                     .Fields(0) = shareNo
  7.                     .Fields(i) = a(1, i)
  8.                 Next i
  9.                 .Update       '§ó·s¸ê®Æªí
  10.             Next
  11.         End With
½Æ»s¥N½X
©Ò¥H§Ú§Æ±æ¥ÎSQL§@¸ê®Æ¼g¤J¡A¦ý½Ð°Ý³o¥y¦p¦ó§ï¼g¦¨¥Î wb ©Îactivebook§@DATABASE©O¡H
  1. "insert into Price select * from (select " & shareNo & " as Share, Date, Open, High, Low, Close, Volume as Vol, [Adj Close] as AClose from [Excel 8.0;hdr=yes;imex=1;Database=" & wb & "].[table$A1:G" & r & "])"
½Æ»s¥N½X
ÁÂÁ«ü±Ð

TOP

¦^´_  ¤p«L«È
§A¤w¦³¿n¤À44¤À  ª©³W: Àɮתþ¥ó­­µ¥¯Å¤¤¾Ç¥Í¡]¿n¤À50¡^¥H¤W¤~¯à¤U¸ü
¥[ªo ¥[ªo!
GBKEE µoªí©ó 2012-8-31 10:24



    ²×©ó¦¨¬°¤¤¾Ç¥Í¤F¡A¥i¥H¸üªþ¥ó¤F
¤Ó§Q®`¤F¡A­ì¨Ó¥i¥H³o¼Ë²¤Æªº¡AÁÂÁ¡I¤º®e¤Ó¦h¡A­nÂI®É¶¡®ø¤Æ

¦ý¥i¥H¦h¤F¸Ñ¤@¤U¡A¥ÎDAO ©MADODB¦b°õ¦æ®Ä²v¤W¦³¨S¦³¤À§O¡H
¦]¬°DAO¤£¥Î¹³ADODB­n¼gprovider=?????¡A®e©ö°O¦í¡C

¥t¥~¡A§Ú¬Ý¨ì¡u¸ê®Æ¾É¤J¸ê®Æ®w()¡v¤¤¡A§A¬O¥ÎFOR LOOP+.AddNew +.UPDATEªº¤èªk¼g¤J¸ê®Æ¡A³o­Ó©M¥ÎSQL COMMANDªºINSERT¡A¦b°õ¦æ³t«×¤W¦³¨S¦³¤À§O¡HÁÂÁÂ

TOP

³o­Ó¤èªk¦n¹³¤£¿ù¡A«Ý§Ú¦^®a§ï¦¨³o­Ó¸Õ¸Õ¡AÁÂÁÂ

TOP

§¹¾ãµ{¦¡½X....
  1. Sub ±NCSVÀɸê®Æ¼g¤JACCESS()

  2.      Dim cn As ADODB.Connection
  3.    
  4.     '«Ø¥ßADODB Connectionª«¥óÅܼÆ
  5.      Set cn = New ADODB.Connection
  6.    
  7.      TARGET_DB = "TaiwanDB.mdb"
  8.      tbl = "PRICE_Daily"
  9.      ªÑ²¼¥N¸¹ = "1101"
  10.      theCsvFolder = ThisWorkbook.Path
  11.    
  12.     '«Ø¥ßACCESS(*.mdb)³sµ²
  13.      cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  14.              "Data Source=" & ThisWorkbook.Path & "\" & TARGET_DB & ";" & _
  15.              "Persist Security Info=False"
  16.          
  17.      strFields = "[Date],[Open],[High],[Low],[Close],[Volume],[Adj Close] as [AdjClose]"
  18.      strSQL = "INSERT INTO [" & tbl & "] SELECT " & ªÑ²¼¥N¸¹ & " as [StockID]," & strFields & " FROM [Text;Database=" & theCsvFolder & "].[" & ªÑ²¼¥N¸¹ & "#CSV]"

  19.     '°õ¦æSQL command
  20.      cn.Execute strSQL
  21.      
  22.     'Ãö³¬ADODB connection
  23.      cn.Close
  24.      
  25.     '²M°£¦û¥Î°O¾ÐÅé
  26.      Set cn = Nothing

  27. End Sub
½Æ»s¥N½X
diabo

TOP

#10 ªº¼gªk¡A¥u¯à¬Ù¤@­Ó¨BÆJ...

Ū¨ú¸ê®Æ > Àx¦s¦¨CSV >  (¥i¬Ù²¤)Ū¨úCSV(¥i¬Ù²¤) > CSVª½±µ¼g¤JACCESS > §R°£CSVªº¹Lµ{[code]
diabo

TOP

¦^´_ 9# ¤p«L«È

ª½±µ±NCSVÀÉ¡A·í§@TABLEªº¥t¤@ºØ¼gªk...
  1. theCsvFolder = ThisWorkbook.Path & "\temp\"   '¤U¸üªºCSV¼È¦s¸ê®Æ§¨¡AÀɦW«h¬°¡iªÑ²¼¥N¸¹.csv¡j
  2. tbl = "PRICE_Daily"   ' ACCESS ¸Ì¦s¤é¦¨¥æ¸ê®ÆªºTABLE

  3.         strFields = "[Date],[Open],[High],[Low],[Close],[Volume],[Adj Close] as [AdjClose]"
  4.         strSQL = "INSERT INTO [" & tbl & "] SELECT " & ªÑ²¼¥N¸¹ & " as [StockID]," & strFields & " FROM [Text;Database=" & theCsvFolder & "].[" & ªÑ²¼¥N¸¹ & "#CSV]"

  5. cn.Execute strSQL
½Æ»s¥N½X
diabo

TOP

¥»©«³Ì«á¥Ñ ¤p«L«È ©ó 2012-8-31 11:09 ½s¿è
¦^´_  ¤p«L«È

[°Ñ¦Ò]
¶¶§Ç¥i§ï¦¨¡G
¤U¸üCSV ¡÷ ¸g¹LVBA¾ã²z¥[¤J¥N¸¹ ¡÷ ¶×¤JAccess¡C

¦Ü©ó¤U¸ü«á¡A ...
HSIEN6001 µoªí©ó 2012-8-31 10:56



    §Ú¤]¤£À´¦p¦ó¦bCSV¥[¤J·sÄæ¦ì¡A©Ò¥H§Ú¥Î¤F¤@­Ó´À¥N¤èªk¡G
  1. mySQL = "insert into Price select * from (select " & shareNo & " as Share, Date, Open, High, Low, Close, Volume as Vol, [Adj Close] as AClose from [Excel 8.0;hdr=yes;imex=1;Database=" & T1 & "].[" & shareNo & "$A1:G" & r & "])"
½Æ»s¥N½X
¥ý§âCSV·í¦¨¤@­ÓDATABASEªºTABLE¡A¦A¥ÎSQL INSERT¨ì§ÚªºACCESS¤¤¡ASQL COMMAND·í¤¤¥[¤W§Ú»Ý­nªºSHARE NO¡A³o¼Ë«K¤£¥Î¥[Äæ¦ì¨ìCSV¤F¡C
¦ý§ÚÁÙ¬Oı±o§Ú²{¦bªº°µªk¦³ÂIÄø¡Aªá¤@½ü¥\¤Ò±N¸ê®Æ¼g¦¨¤@­ÓCSV¡A¦A¥ÎSQL§â¨S¦³ªº¸ê®Æ(SHARE NO)¥[¤W¡AIMPORT¨ìACCESS¡A¦A§R±¼¨º­ÓCSV¡A¦ý§ÚÁ`ı±o«Ø¥ßCSVªº¤u§Ç¦³ÂI­«½Æ......

TOP

¦^´_ 6# GBKEE


    ¦nªº¡A«Ý§Ú¥ý¦^À³¤j®aªºPOST¦A§@¬ã¨s¡A¥ýÁ¤F

TOP

¦^´_ 4# ¤p«L«È

[°Ñ¦Ò]
¶¶§Ç¥i§ï¦¨¡G
¤U¸üCSV ¡÷ ¸g¹LVBA¾ã²z¥[¤J¥N¸¹ ¡÷ ¶×¤JAccess¡C

¦Ü©ó¤U¸ü«á¡A¨Ì§t¦³¡i¥N¸¹¡j¤§ÀɮצWºÙµ¹¸ÓÀÉ·s¼W¤@­Ó¡i¥N¸¹Äæ¦ì¡j¡A³o¤è­±§A¥i¥t¥~¸ß°Ý¥ý¶i¡A´M¨D¸Ñ¨M¤è®×¡F³o³¡¥÷§ÚÁÙ¨S¾Ç¨ì¡C
¡ã ^___^ ¡ã¦R¦Þ¶Ì¯º!

TOP

        ÀR«ä¦Û¦b : ¤Hªº²´·úªø¦b«e­±¡A¥u¬Ý¨ì§O¤Hªº¯ÊÂI¡Aµ·²@¬Ý¤£¨ì¦Û¤vªº¯ÊÂI¡C
ªð¦^¦Cªí ¤W¤@¥DÃD