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

½Ð°Ý¦p¦ó§ì¨újavascriptªº*.csvÀɮסH

½Ð°Ý¦p¦ó§ì¨újavascriptªº*.csvÀɮסH

·Q½Ð±Ð¤@¤U¡A§Ú­n¥Î§å¦¸§ì¨úºô­¶¤¤ªº*csvÀÉ¡AµM«á§â¸Ì­±ªº¸ê®Æ©ñ¤Jexcelªºªí®æ¤¤¡A¦ýºô­¶¤¤ªºÀɮ׳sµ²¬O¥ÎjavascriptÂð_¨Ó¡A®×¨Ò¦p¤U¡G

http://prtr.epa.gov.tw/resultEMS.aspx?emsno=A36A0770&tab=Panel5

§Ú¥´ºâ¦s©ñªºexcelÀɤw¸g¦³ºÞ¨î½s¸¹¦Cªí¡AµM«á´N®Ú¾Ú³o­Ó¦Cªí¥h§ì¨ú»Ý­nªº¸ê®Æ¡A¤£¹L¦b§ì*csv³o­Ó¦a¤è´N¥d¦í¤F¡C

ÁÂÁÂ

¦^´_ 1# torrent
¨t²Î¦£¸L¤¤¡A½Ðµy«á¦A¦¸¬d¸ß¡C

¨t²ÎÃa¤F¶Ü¡A¤â°Ê³£¤£¯à¤U¸ü¡C¡C¡C

TOP

¦n¹³¬O­C¡A§Ú«e´X¤Ñ¸ÕÁÙ¥¿±`¡C

TOP

¦^´_ 3# torrent



¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Sh As Worksheet, Rng As Range
  4.     Application.ScreenUpdating = False
  5.     Application.DisplayAlerts = False
  6.     Set Rng = Sheets("Sheet1").Range("A2")
  7.     On Error Resume Next
  8.     Set Sh = Sheets.Add
  9.     With Sh.QueryTables.Add("URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5", Sh.[A1])
  10.         .WebSelectionType = xlSpecifiedTables
  11.         .WebFormatting = xlWebFormattingNone
  12.         .WebTables = """GridView5"""
  13.         .WebPreFormattedTextToColumns = True
  14.         .WebConsecutiveDelimitersAsOne = True
  15.         .WebSingleBlockTextImport = False
  16.         .WebDisableDateRecognition = False
  17.         .WebDisableRedirections = False
  18.         .Refresh BackgroundQuery:=False
  19.     End With
  20.     Do While Rng <> ""
  21.         With Sh.QueryTables(1)
  22.             Rng.Offset(, 1).Range("A1:I1").Value = IIf(Err.Number = 0, Sh.QueryTables(1).ResultRange.Rows(2).Value, "")
  23.             Err.Clear
  24.             Set Rng = Rng.Offset(1)
  25.             .Connection = "URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5"
  26.             .Refresh BackgroundQuery:=False
  27.         End With
  28.     Loop
  29.     Sh.Delete
  30.     Application.DisplayAlerts = True
  31.     Application.ScreenUpdating = True
  32. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¤Ó·PÁ¤F¡I

§Úµo²{¦³¨Çªí®æ¬O¦h©ó¤@µ§¸ê®Æªº¡A©Ò¥H¤@­ÓºÞ¨î½s¸¹ªº¸ê®Æ¦³¥i¯à·|¦³¤@µ§¡B¨âµ§¬Æ¦Ü10µ§¡A¨Ò¦p³o¸Ì¡G

http://prtr.epa.gov.tw/resultEMS.aspx?emsno=E4901607&tab=Panel5

§Úª¦¤F¤@¤U¤å¨Ãgoogle¡A¥»¨Ó·Q¥ÎResultRange.Rows.Count³o­Ó«ü¥O¨Óºâtableªº¦C¼Æ«á¡A¥ý¥HRange().EntireRow.insert´¡¤J©Ò»Ý­nªº¦C¼Æ¡AµM«á¦A¥HResultRange.Rows(i)¥[¤J¼Æ¾Ú¡A¦ý«ç»ò¸Õ³£¬OªÅ¥Õ¡A¤£ª¾¹D¤j¤j¦³¨S¦³¦nªº¿ìªk¡H

ÁÂÁÂ

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-1-5 06:52 ½s¿è

¦^´_ 5# torrent
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Sh As Worksheet, Rng As Range, Q As Variant
  4.     Application.ScreenUpdating = False
  5.     Set Rng = Sheets("Sheet1").Range("A2")  'ºÞ¨î½s¸¹
  6.     On Error GoTo ER
  7.     With Sheets("ºÞ¨î¤º®e")
  8.         Set Sh = Sheets(.Name)
  9.         .UsedRange = ""
  10.     End With
  11.     On Error Resume Next
  12.     With Sh.QueryTables.Add("URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5", Sh.[AA1])
  13.         .WebSelectionType = xlSpecifiedTables
  14.         .WebFormatting = xlWebFormattingNone
  15.         .WebTables = """GridView5"""
  16.         .WebPreFormattedTextToColumns = True
  17.         .WebConsecutiveDelimitersAsOne = True
  18.         .WebSingleBlockTextImport = False
  19.         .WebDisableDateRecognition = False
  20.         .WebDisableRedirections = False
  21.         .Refresh BackgroundQuery:=False
  22.     End With
  23.     Set Q = Sh.QueryTables(1)
  24.     Do While Rng <> ""
  25.         If Err = 0 And Application.Count(Q.ResultRange) > 0 Then
  26.             With Sh.Cells(Sh.Rows.Count, 2).End(xlUp)
  27.                 .Offset(1, -1) = Rng
  28.                 If .Row = 1 Then
  29.                     .Offset(, -1) = "ºÞ¨î½s¸¹"
  30.                     Q.ResultRange.Copy .Cells
  31.                 Else
  32.                     Q.ResultRange.Rows("2:" & Q.ResultRange.Rows.Count).Copy .Offset(1)
  33.                 End If
  34.             End With
  35.         End If
  36.         Err.Clear
  37.         Set Rng = Rng.Offset(1)
  38.         Q.Connection = "URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5"
  39.         Q.Refresh BackgroundQuery:=False
  40.     Loop
  41.     Q.ResultRange = ""
  42.     With Sh
  43.         .Columns.AutoFit
  44.         For Each Q In .Names
  45.            Q.Delete
  46.         Next
  47.         For Each Q In .QueryTables
  48.            Q.Delete
  49.         Next
  50.     End With   
  51.    Application.ScreenUpdating = True
  52.    Exit Sub
  53. ER:
  54.     If Err.Number = 9 Then
  55.         Sheets.Add.Name = "ºÞ¨î¤º®e"
  56.         Resume
  57.     End If
  58. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¤Ó·P¿E¤F¡A§Ú³o´X¤Ñ­×¥¿¤F¤@¨Ç¸Ì­±ªºµ{¦¡½X¡AÅý¥¦¤]¥i¥H§ì§Oªº¸ê·½¡C«D±`·PÁ¡I

¶¶«K°Ý¤@¤U¡A³o¸Ì¤£§ìcsv¦Ó¬O§ìºô­¶ªºtable¡A¬O¦]¬°csv¤¤¤å¶i¨Ó¬O¶Ã½X¦Ó¤SµL¸Ñªº­ì¦]¶Ü¡H

TOP

¦^´_ 7# torrent
³oºô­¶csv¤£¬OµLªk¤U¸ü¶Ü!,
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¤£¦n·N«ä¡A§Ú¬O¦]¬°«á¨Ó­n¨ìÀô«O¸p¥t¤@­Óopendataºô¯¸§ìcsvªº®É­Ôµo²{§ì¶i¤u§@ªí³£·|Åܦ¨¶Ã½X¡A©Ò¥H¤~Áp·Q¨ì¡C

http://opendata.epa.gov.tw/Data/Contents/EMS/

³o­Óºô¯¸©M¤§«e¨º­Ó²Ä¤@¼Óªººô¯¸À³¸Ó¬O³qªº¡A¦ý³o¸Ìcsv´Nª½±µ´£¨Ñ©Ò¦³³æ¦ìªººÞ¨î½s¸¹¡A¦ý¤@¦¸´£¨Ñ1000µ§¡A©Ò¥HÁ`¦@7¸U¦hµ§­n¤U¸ü71¦¸csvÀɮסC

ÁöµM§Ú¥u¬O­n³Ì­«­nªººÞ¨î½s¸¹¡A¦ý¨ä¥¦³£¶Ã½XÁÙ¬Oı±o«Ü©Ç¡A¥H¤U¬O§Úªºcode¡A§ÚÁÙ¬Oªì¾ÇªÌ¡A¥Î³Ì²³æªºdo/loop¨Ó³B²z°j°é¡A¶]¨ì¤@¥b´N¥d¦í¤F¡A¤£ª¾¹D¥X¤F¤°»ò¨Æ±¡¡A¦hÁ¡I
  1. Sub csv()

  2.     Dim i As Integer, k As Integer, emsUrl As String
  3.    
  4.     Set i = 0
  5.    
  6.     Set k = 1000
  7.    
  8.     emsUrl = "http://opendata.epa.gov.tw/ws/Data/EMS/?$orderby=RegistrationNo&$skip=" & i & "&$top=" & k & "&format=csv"
  9.    
  10.     With ActiveSheet.QueryTables.Add(Connection:="URL;" & emsUrl, Destination:=Range("A2"))
  11.    
  12.         .BackgroundQuery = True
  13.         .RefreshStyle = xlOverwriteCells
  14.         .RefreshPeriod = 0
  15.         .AdjustColumnWidth = False
  16.         .WebSelectionType = xlSpecifiedTables
  17.         .WebFormatting = xlWebFormattingNone
  18.          
  19.     End With
  20.    
  21. End Sub
½Æ»s¥N½X

TOP

©êºp¡A­è­è¶K¿ùcode¤F¡A¦ý¤w¸g¤£¯à½s¿è¡G
  1. Sub csv()

  2.     Dim i As Integer, k As Integer, emsUrl As String, Rng As Range
  3.    
  4.     i = 1
  5.    
  6.     k = 1000

  7.     Do Until k = 71000

  8.     Set Rng = Sheets("Sheet1").Range("A" & i & "")

  9.     emsUrl = "http://opendata.epa.gov.tw/ws/Data/EMS/?$orderby=RegistrationNo&$skip=" & i & "&$top=" & k & "&format=csv"
  10.    
  11.     With ActiveSheet.QueryTables.Add(Connection:="URL;" & emsUrl, Destination:=Rng)
  12.    
  13.         .BackgroundQuery = True
  14.         .RefreshStyle = xlOverwriteCells
  15.         .RefreshPeriod = 0
  16.         .AdjustColumnWidth = False
  17.         .WebSelectionType = xlSpecifiedTables
  18.         .WebFormatting = xlWebFormattingNone
  19.          
  20.     End With
  21.    
  22.     i = i + 1000

  23.     k = k + 1000

  24.     Loop

  25. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¦³¦h¤Ö¤O¶q´N°µ¦h¤Ö¨Æ¡A¤£­n¤ß¦sµ¥«Ý¡Aµ¥«Ý¤~·|¸¨ªÅ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD