ªð¦^¦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

ÁÂÁÂ

¦^´_ 13# GBKEE

¦hÁ¡A³o¼Ë¶]¥X¨Óªºµ²ªG¨S¦³°ÝÃD¤F¡C

TOP

¦^´_ 12# torrent
  1.            '.Resize(Q.ResultRange.Rows.Count, 1).Offset(2, -1).Value = Rng
  2.                     .Resize(Q.ResultRange.Rows.Count - 1, 1).Offset(1, -1).Value = Rng
  3.                     'Q.ResultRange.Rows.Count - 1 ->¤£¥]§tªíÀYªº¦C¼Æ
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 11# GBKEE

¨ü±Ð¤F¡A­ì¨Ó­n¥ÎWorkbooks¡C

¥t¥~¡A§Ú¦bGBKEE¤j¤jÀ°§Ú­×¥¿ªº²Ä¤G­Ócode¤¤°µ¤F¤@¨Ç­×¥¿¡A¥Øªº¬O§âAÄ檺ºÞ¨î½s¸¹¶ñº¡¡A§Ú¦b²Ä31¦C¥[¤F³o¤@¦æ¡G

.Resize(Q.ResultRange.Rows.Count, 1).Offset(2, -1).Value = Rng

¬Ý°_¨Ó°£¤F³Ì«á¤@­ÓºÞ¨î½s¸¹·|¦h¨â¦æ§À¤Ú¤§¥~¡A¦n¹³¨S¦³¨ä¥¦ªº°ÝÃD¡A¤£ª¾¹D¦U¦ì¦³¨S¦³§ó¦nªº·N¨£©Î¬Ý¥X³o¼Ë·d·|¦³bug¡H

ÁÂÁÂ

  1. Sub punish()
  2.     Dim Sh As Worksheet, Rng As Range, Q As Variant
  3.     Application.ScreenUpdating = False
  4.     Set Rng = Sheets("Sheet1").Range("A2")  'ºÞ¨î½s¸¹
  5.     On Error GoTo ER
  6.     With Sheets("ºÞ¨î¤º®e")
  7.         Set Sh = Sheets(.Name)
  8.         .UsedRange = ""
  9.     End With
  10.     On Error Resume Next
  11.     With Sh.QueryTables.Add("URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5", Sh.[AA1])
  12.         .WebSelectionType = xlSpecifiedTables
  13.         .WebFormatting = xlWebFormattingNone
  14.         .WebTables = """GridView5"""
  15.         .WebPreFormattedTextToColumns = True
  16.         .WebConsecutiveDelimitersAsOne = True
  17.         .WebSingleBlockTextImport = False
  18.         .WebDisableDateRecognition = False
  19.         .WebDisableRedirections = False
  20.         .Refresh BackgroundQuery:=False
  21.     End With
  22.     Set Q = Sh.QueryTables(1)
  23.     Do While Rng <> ""
  24.         If Err = 0 And Application.Count(Q.ResultRange) > 0 Then
  25.             With Sh.Cells(Sh.Rows.Count, 2).End(xlUp)
  26.                 .Offset(1, -1) = Rng
  27.                 If .Row = 1 Then
  28.                     .Offset(, -1) = "ºÞ¨î½s¸¹"
  29.                     Q.ResultRange.Copy .Cells
  30.                 Else
  31.                     .Resize(Q.ResultRange.Rows.Count, 1).Offset(2, -1).Value = Rng
  32.                     Q.ResultRange.Rows("2:" & Q.ResultRange.Rows.Count).Copy .Offset(1)
  33.                     
  34.                 End If
  35.             End With
  36.         End If
  37.         Err.Clear
  38.         Set Rng = Rng.Offset(1)
  39.         Q.Connection = "URL;http://prtr.epa.gov.tw/resultEMS.aspx?emsno=" & Rng & "&tab=Panel5"
  40.         Q.Refresh BackgroundQuery:=False
  41.     Loop
  42.     Q.ResultRange = ""
  43.     With Sh
  44.         .Columns.AutoFit
  45.         For Each Q In .Names
  46.            Q.Delete
  47.         Next
  48.         For Each Q In .QueryTables
  49.            Q.Delete
  50.         Next
  51.     End With
  52.    Application.ScreenUpdating = True
  53.    Exit Sub
  54. ER:
  55.     If Err.Number = 9 Then
  56.         Sheets.Add.Name = "ºÞ¨î¤º®e"
  57.         Resume
  58.     End If
  59. End Sub
½Æ»s¥N½X

TOP

¦^´_ 10# torrent
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()  '¥þ³¡¸ê®Æ¶W¹L 65536µ§ 2003ª©¤£¾A¥Î
  3.     Dim Sh As Worksheet, wb As Workbook, i As Long
  4.     Set Sh = ActiveWorkbook.Sheets(1)
  5.     Sh.UsedRange = ""
  6.     i = 0
  7.     Do
  8.         Workbooks.OpenText Filename:="http://opendata.epa.gov.tw/ws/Data/EMS/?$orderby=RegistrationNo&$skip=" & i & "&$top=1000&format=csv" _
  9.             , Origin:=-535, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
  10.             xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
  11.             Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
  12.             Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
  13.             Array(9, 1), Array(10, 1), Array(11, 1)), TrailingMinusNumbers:=True
  14.         With ActiveWorkbook.Sheets(1).UsedRange
  15.             If .Cells(1) = "" Then Exit Do
  16.             If i = 0 Then
  17.                 .Copy Sh.[a1]
  18.             Else
  19.                 .Offset(1).Copy Sh.[a1].End(xlDown).Offset(1)
  20.             End If
  21.             ActiveWorkbook.Close False
  22.         End With
  23.     i = i + 1000
  24.    Loop
  25.     ActiveWorkbook.Close False
  26. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

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

¤£¦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

¦^´_ 7# torrent
³oºô­¶csv¤£¬OµLªk¤U¸ü¶Ü!,
·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

¥»©«³Ì«á¥Ñ 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

        ÀR«ä¦Û¦b : ¤H¥Í¤£¤@©w²y²y¬O¦n²y¡A¦ý¬O¦³¾ú½mªº±j¥´ªÌ¡AÀH®É³£¥i¥H´§´Î¡C
ªð¦^¦Cªí ¤W¤@¥DÃD