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

½Ð°Ý³o­Óºô­¶¦p¦ó¥ÎWEB¬d¸ß¿é¤Jexcel

ª©¤jªGµM¤Ó±j¤j¤F¡I
®Ú¾Úª©¤jªºcode¡A¥é·Ó¤F¥t¤@­Óºô­¶ªºWEB¿é¤J
portal.sw.nat.gov.tw/PPL/pages/integration/layout.jsp?appId=APGQAGB309
ºô­¶¬d¸ßµe­±¦p¤U¡G

¶×¤JEXCELµe­±¦p¤U¡G

-----------------------------code---------------------------------------
Option Base 1
Sub Ex()
    Dim Ar, AA(), ¥X¤f³ø³æ¸¹½X As String, Sh As Worksheet
    ¥X¤f³ø³æ¸¹½X = InputBox("¥X¤f³ø³æ¸¹½X", "¥X¤f³ø³æ©ñ¦æ¸ê®Æ¬d¸ß", "BE  02XE580024")
    If ¥X¤f³ø³æ¸¹½X = "" Then Exit Sub
    Set Sh = ActiveSheet                                 '«ü©wÅã¥Ü¸ê®Æªº¤u§@ªí 'ActiveSheet->§@¥Î¤¤ªº¤u§@ªí
    With CreateObject("Microsoft.XMLHTTP")
       .Open "GET", "http://portal.sw.nat.gov.tw/APGQ/GB309!query?&choice=D&declNo=" & ¥X¤f³ø³æ¸¹½X, False
        .send
        Ar = Split(Replace(.responsetext, """", ""), ",")
        AA = Array(1, 8, 4, 7, 2, 14, 11)           'Aø󪺼ÐÃD¤º®e Ar¤¤°}¦C¹ïÀ³¤§¯Á¤Þ­È
        On Error GoTo Er                            '¥X¤f³ø³æ¸¹½X ¤£¥¿½T·|¦³¿ù»~:
        For i = 1 To UBound(AA)
            Sh.Cells(1 + i, "B") = Split(Ar(AA(i)), ":")(1)  'Bøó
       Next
       AA = Array(5, 3, 10, 6, 12, 9)                 'Cø󪺼ÐÃD¤º®e Ar¤¤°}¦C¹ïÀ³¤§¯Á¤Þ­È
       For i = 1 To UBound(AA)
            Sh.Cells(2 + i, "D") = Split(Ar(AA(i)), ":")(1)  'Døó
            If AA(i) = 6 Then Cells(2 + i, "D") = Replace(Cells(2 + i, "D"), "\/", "/")
       Next
    End With
    Exit Sub
Er:
    Sh.[b2].Resize(7, 1) = ""
    Sh.[d2].Resize(7, 1) = ""
End Sub
-----------------------------code---------------------------------------
½Ð°Ýª©¤j¦p¦ó§â¤º®eªº¶Ã½X§ó§ï¦¨¥¿½Tªº¤¤¤åÅã¥Ü¡A¦p¡G«Ø·s°ê»ÚªÑ¥÷¦³­­¤½¥q°ª¶¯¤À¤½¥q¡Aªøºa°ê»Ú...

¨ä¹ê¡A¦Û¤v¤ñ¸û°½Ãi¡A°µªºiqy¥u¦³¥H¤U²³æ¤º®e¡A°Ñ·ÓEXCEL¤ºªº³ø³æ¸¹½X¥i°µ§å¦¸ªº¬d¸ß¡A
¥u¬O¦^¶Çªºµ²ªG¦pjoey0415¥S»¡ªº·|¦³¶Ã½X¡A¦pªG¦³¤èªk¥i¥H¸Ñ¨M¦^¶Ç¶Ã½Xªº¸Ü´N¤Ó¦n¤F~~
------------------------------------------
WEB
1
http://portal.sw.nat.gov.tw/APGQ/GB309!query
choice=D&declNo=["ID",""]

Selection=1
Formatting=None
------------------------------------------
Hi~

TOP

¦^´_ 10# GBKEE
·PÁ¡A Ex() °õ¦æ¥X¨Óªºµ²ªG¹êµLªk¤J¥Ø¡AÁÙ¬O±z­ì¨Óªºµ{¦¡½X¸û¨Î¡A
¦Ü©ó "¼ÐÃD" ªº°ÝÃD§Ú¶i¤J Html ¬Ý¤F¤@¤U¡AÁŵM¤j®©¡A­ì¨Ó¥¦¬O
¨Ï¥Î <TD> </TD> ³B­ù¡A©Ò¥H¤]¥u¦n·Ó³æ¤J®y¤F¡C

TOP

¦^´_ 10# GBKEE

½Ð°Ý¶W¯Åª©¥D

³z¹L±zªº¤èªk¡A¤j·§ª¾¹D«ç»ò¤Á¡A§Ú¥u·|ª©¥Dªº¤è¦¡­×§ï¦p¤U¡G
  1.     Sub Ex()
  2.         Dim Ar, AA(), ¥X¤f³ø³æ¸¹½X As String, Sh As Worksheet
  3.         ¥X¤f³ø³æ¸¹½X = InputBox("¥X¤f³ø³æ¸¹½X", "¥X¤f³ø³æ©ñ¦æ¸ê®Æ¬d¸ß", "BE  02XE580024")
  4.         If ¥X¤f³ø³æ¸¹½X = "" Then Exit Sub
  5.         Set Sh = ActiveSheet                                 '«ü©wÅã¥Ü¸ê®Æªº¤u§@ªí 'ActiveSheet->§@¥Î¤¤ªº¤u§@ªí
  6.         With CreateObject("Microsoft.XMLHTTP")
  7.            .Open "GET", "http://portal.sw.nat.gov.tw/APGQ/GB315!query?declNo=" & ¥X¤f³ø³æ¸¹½X, False
  8.             .send
  9.             Ar = Split(Replace(.responsetext, """", ""), ",")
  10.             For i = 0 To UBound(Ar)
  11.                 Sh.Cells(1 + i, 1) = Ar(i)  'Bøó
  12.            Next
  13.            
  14.             For i = 0 To UBound(Ar)
  15.                 Sh.Cells(1 + i, 2) = Split(Sh.Cells(1 + i, 1), ":")(0) 'Bøó
  16.                 Sh.Cells(1 + i, 3) = Split(Sh.Cells(1 + i, 1), ":")(1) 'Bøó
  17.            Next
½Æ»s¥N½X


½Ð°Ýª©¥D¡G
AA = Array(1, 8, 4, 7, 2, 14, 11)           'Aø󪺼ÐÃD¤º®e Ar¤¤°}¦C¹ïÀ³¤§¯Á¤Þ­È
AA = Array(5, 3, 10, 6, 12, 9)                 'Cø󪺼ÐÃD¤º®e Ar¤¤°}¦C¹ïÀ³¤§¯Á¤Þ­È

¬O¬°¤F¤è«K«ü©wAR°}¦C¤¤«ü©wªº¤¸¯À¡A¦b©ñ¶i·Q­nªºCELLS¤¤¶Ü¡H

============================
           On Error GoTo Er                            '¥X¤f³ø³æ¸¹½X ¤£¥¿½T·|¦³¿ù»~:

¥¦¸õ¨ì
Er:
        Sh.[b2].Resize(7, 1) = ""
        Sh.[d2].Resize(7, 1) = ""
­nÅý³o¨âÄæ³£³]¬°ªÅ¦r¦ê¶Ü¡H

¦pªG­n§å¦¸§ä100­È©ñ¶i¥h¶]¦^°é¡A¤¤¶¡¦³¿ùªº¸Ü
­n©ñ on error resume next¶Ü¡H
©Î¬O³o¨â­Ó¤è¦¡¦³¤À§O¶Ü¡H

ÁÂÁÂ

TOP

¬O¬°¤F¤è«K«ü©wAR°}¦C¤¤«ü©wªº¤¸¯À¡A¦b©ñ¶i·Q­nªºCELLS¤¤¶Ü?
¦pªG­n§å¦¸§ä100­È©ñ¶i¥h¶]¦^°é¡A¤¤¶¡¦³¿ùªº¸Ü
­n©ñ on error resume next¶Ü¡H
¦^´_ 13# joey0415
¨S¿ù¬O­n©ñ¶i·Q­nªºCELLS.

¦pªG¹w´Á·|¦³¿ù»~ªºµ{¦¡½X¤§«e ¼g¤W on error resume next ,µ{¦¡´N¤@ª½°õ¦æ¤U¥h,¦p¯u¦³¿ù»~§A¬O·|¤£ª¾¹Dªº
¦^´_ 11# jewayy

  1. Option Explicit
  2. Option Base 1
  3. Sub ¤f³ø³æ³qÃö¬yµ{¬d¸ß()
  4.     Dim ¥X¤f³ø³æ¸¹½X As String, Rng As Range, AR, S As Variant, E As Variant, i As Integer, W As String, II As Integer
  5.     Dim Sh As Worksheet
  6.     ¥X¤f³ø³æ¸¹½X = InputBox("¥X¤f³ø³æ¸¹½X", "¥X¤f³ø³æ©ñ¦æ¸ê®Æ¬d¸ß", "BE  02XE580024")
  7.     If ¥X¤f³ø³æ¸¹½X = "" Then Exit Sub
  8.     Set Sh = ActiveSheet
  9.     '«ü©wÅã¥Ü¸ê®Æªº¤u§@ªí 'ActiveSheet->§@¥Î¤¤ªº¤u§@ªí
  10.     Set Rng = Sh.Range("b2:B9, D3:D7, D9, B11, D11")
  11.     '**AR¤º®e: °Ñ·Ó **** ¥X¤f³ø³æ³qÃö¬yµ{¬d¸ß(GB309) ºô­¶ªº­ì©lÀÉ*****
  12.     AR = Array("transTypeCd", "vslRegNo", "declNo", "brokerBoxNoName", "mawb", "hawb", "declType", "relCondSubCd" _
  13.     , "soNo", "custCd", "carrierAgencyCd", "arrangeNo", "examMethod", "debitMark", "firstSendDate", "lastSendDate")
  14.     With CreateObject("Microsoft.XMLHTTP")
  15.        .Open "GET", "http://portal.sw.nat.gov.tw/APGQ/GB309!query?&choice=D&declNo=" & ¥X¤f³ø³æ¸¹½X, False
  16.         .send
  17.         S = Replace(.responsetext, """", "")
  18.     End With
  19.     i = 1
  20.     '*********** ¬d¸ßµ²ªG *****
  21.     For Each E In Rng
  22.         E = ""
  23.         If InStr(S, AR(i)) Then
  24.             W = Mid(Split(Mid(S, InStr(S, AR(i)) + Len(AR(i))), ",")(0), 2)
  25.             E = IIf(InStr(LCase(W), "null"), "", W)
  26.         End If
  27.         i = i + 1
  28.     Next
  29.     '***************³qÃö¬yµ{**********
  30.     AR = Split(S, "data:[")(1)                          'ÄdºI "data:[" «áªº¦r¦ê
  31.     AR = Split(AR, "]")(0)                              'ÄdºI "[" «eªº¦r¦ê
  32.     AR = Replace(Mid(AR, 2, Len(AR) - 2), "null", " ")  '´À´« "null" ¬° " "
  33.     AR = Replace(AR, "T", " ")                          '´À´«  "T"   ¬° " "
  34.     AR = Split(AR, "},{")                               '¥H "},{" ¤À³Î¬°°}¦C
  35.     S = Array(4, 2, 0, 1, 3)
  36.     Sh.Range("A13").CurrentRegion.Offset(1) = ""
  37.     For i = 0 To UBound(AR)
  38.         For II = 0 To UBound(S) - 1
  39.             E = Split(AR(i), ",")(S(II + 1))            '¥H S(II + 1)ªº­È ¨ú±o Split(AR(i), ",")°}¦Cªº¯Á¤Þ­È
  40.             Sh.Cells(i + 14, "A").Offset(, II) = Mid(E, InStr(E, ":") + 1)
  41.         Next
  42.     Next
  43. End Sub
  44. '¥X¤f³ø³æ³qÃö¬yµ{¬d¸ß(GB309) ºô­¶ªº­ì©lÀÉ
  45. '<td class="resultHeader">®üªÅ¹B§O</td><td id="transTypeCd" class="result">
  46. '<td class="resultHeader" width="25%">®üÃö³qÃö¸¹½X</td><td width="25%" id="vslRegNo" class="result">
  47. '<td class="resultHeader" width="25%">¸Ë³f³æ½s¸¹</td><td width="25%" id="soNo" class="result">
  48. '<td class="resultHeader">³ø³æ¸¹½X</td><td id="declNo" class="result">
  49. '<td class="resultHeader">Ãö°Ï¥N½X</td><td id="custCd" class="result">
  50. '<td class="resultHeader">³øÃö·~ªÌ½c¸¹</td><td id="brokerBoxNoName" class="result">
  51. '<td class="resultHeader">¹B¿é·~ªÌ/¥N²z¦æ¥N½X</td><td id="carrierAgencyCd" class="result">
  52. '<td class="resultHeader">°U¹B³æ¥D¸¹</td><td id="mawb" class="result">
  53. '<td class="resultHeader">²z³æ¸¹½X</td><td id="arrangeNo" class="result">
  54. '<td class="resultHeader">°U¹B³æ¤À¸¹</td><td id="hawb" class="result">
  55. '<td class="resultHeader">¥Ó½Ð¼fÅç¤è¦¡</td><td id="examMethod" class="result">
  56. '<td class="resultHeader">³ø³æÃþ§O</td><td id="declType" class="result">
  57. '<td class="resultHeader">©ñ¦æªþ±a±ø¥ó</td><td id="relCondSubCd" class="result">
  58. '<td class="resultHeader">¬O§_¬°¨R°hµ|e¤Æ³ø³æ</td><td id="debitMark" class="result">
  59. '<tr><td colspan="4" class="resultHeader">¶Ç°eÁ`ÃB¥æ¬d¦Ü°]µ|¤¤¤ßªº¤é´Á</td>
  60. '<td class="resultHeader">²Ä¤@¦¸¶Ç°e¤é´Á</td><td id="firstSendDate" class="result">
  61. '<td class="resultHeader">³Ì«á¤@¦¸¶Ç°e¤é´Á</td><td id="lastSendDate" class="result">
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 14# GBKEE
ÁÂÁ±z¸ÔºÉªº¸Ñ»¡¡A²×©ó°ÝÃD¸Ñ¨M¤F¡C­ì¦]¬O¦­¤W°õ¦æ®É
Åã¥Ü¦b Excel ªí³æ¤Wªº¬O¤@°ï¶Ã½X¡C¤U¤È§Ú¥Î Debug ¤è¦¡
°õ¦æ¤~µoı¬O Explorer ªº¸ÑĶ°ÝÃD¡CIE (10) »P  Firefox ¨âªÌ
ªº Decode ¦³¨Ç·Lªº®t²§¡A¦p³z¹L IE ¶Ç¤J­È·|¦³¶Ã½X¡A¤Ï¤§¡B
«h¤@¤Á¥¿±`¡A ¦p¤U¡G
  1. {"msg":"[°õ¦æ¦¨¥\]","transTypeCd":"®ü","totGrossWeight":49376,"destCd":"VNCLI",
  2.   "totPackQty":"32","declType":"G5","relDate":"102\/09\/17",
  3. "totPackQtyUnit":"PLT","declNo":"BE  02XE580024","vslSign":"BKHC",
  4. "examRelNote":"Y","voyageFlightNo":"1084-186S","marketMftNote":"Y",
  5. "status":"ok","vslName":"UNI-PROSPER                        "}
½Æ»s¥N½X
§Ú±N Ar = Split(Replace(.responsetext, """", ""), ",") µyµy­×§ï¦p¤U¡G
  1. Ar = Split(Trim(Replace(Replace(.responsetext, """", ""), "}", "")), ",")
½Æ»s¥N½X
  1. Ar(0) =  "msg:[°õ¦æ¦¨¥\]"
  2. Ar(1) =  "transTypeCd:®ü"
  3. Ar(2) =  "totGrossWeight":49376
  4. Ar(3) =  "destCd:VNCLI"
  5. Ar(4) =  "totPackQty:32"
  6. Ar(5) =  "declType:G5"
  7. Ar(6) =  "relDate:102\/09\/17"
  8. Ar(7) =  "totPackQtyUnit:PLT"
  9. Ar(8) =  "declNo:BE  02XE580024"
  10. Ar(9) =  "vslSign:BKHC"
  11. Ar(10) =  "examRelNote:Y"
  12. Ar(11) =  "voyageFlightNo:1084-186S"
  13. Ar(12) =  "marketMftNote:Y"
  14. Ar(13) =  "status:ok"
  15. Ar(14) =  "vslName:UNI-PROSPER"
½Æ»s¥N½X
¦p¦¹°õ¦æ°_«KµL·åÒ¯¤F¡AÁÂÁ±z¡I

TOP

¥»©«³Ì«á¥Ñ joey0415 ©ó 2013-11-17 20:58 ½s¿è

¦^´_ 15# c_c_lai

Ar = Split(Trim(Replace(Replace(.responsetext, """", ""), "}", "")), ",")

½Ð°Ýµ{¦¡½Xªº³Ì¤¤ªº®Ö¤ß¬l¸Ñ¦¨°}¦C¡A¦A¤À¬l®É»Ý­n¥t©R°}¦C¶Ü¡H§_«h¦A¬l¸Ñ®É

¤ñ¦p¬l¦¨¤­­Ó¤¸¯À¡A¥i¥H¦A¦P®É©¹¤U¤@°_¬l¶Ü¡H

ÁÂÁÂ
============================
§Ú¬Ý¿ù¤F¡A­ì¨Ó¬O¥ý¨ú¥N
" =>ªÅ¦r¦ê
}=>ªÅ¦r¦ê

{=>ªÅ¦r¦ê
\=>ªÅ¦r¦ê

³Ì«á¤~¬l¤À

TOP

¦^´_ 16# joey0415
  1.         '  http://portal.sw.nat.gov.tw/APGQ/GB315!query?declNo=BE++02XE580024
  2.         '  "GET" ¶Ç¤J (Send) ¤§ XML ¤º®e¡G
  3.         '  {"msg":"[°õ¦æ¦¨¥\]","transTypeCd":"®ü","totGrossWeight":49376,"destCd":"VNCLI",
  4.         '  "totPackQty":"32","declType":"G5","relDate":"102\/09\/17",
  5.         '  "totPackQtyUnit":"PLT","declNo":"BE  02XE580024","vslSign":"BKHC",
  6.         '  "examRelNote":"Y","voyageFlightNo":"1084-186S","marketMftNote":"Y",
  7.         '  "status":"ok","vslName":"UNI-PROSPER                        "}
  8.         AR = Split(Trim(Replace(Replace(.responsetext, """", ""), "}", "")), ",")
  9.         '  ¥ý¥h°£ "¡B¦AªÌ¥h°£ }¡B±µ¤U¨Ó¦A±N«e«áªÅ¥Õ (Space) ²MªÅ¡F³Ì«á¤~³B²z Split() ¨Ã Assign µ¹ AR
  10.         '  Ar :  Variant/String(0 to 14)
  11.         '  Ar(0) =  "msg:[°õ¦æ¦¨¥\]"
  12.         '  Ar(1) =  "transTypeCd:®ü"
  13.         '  Ar(2) =  "totGrossWeight":49376
  14.         '  Ar(3) =  "destCd:VNCLI"
  15.         '  Ar(4) =  "totPackQty:32"
  16.         '  Ar(5) =  "declType:G5"
  17.         '  Ar(6) =  "relDate:102\/09\/17"
  18.         '  Ar(7) =  "totPackQtyUnit:PLT"
  19.         '  Ar(8) =  "declNo:BE  02XE580024"
  20.         '  Ar(9) =  "vslSign:BKHC"
  21.         '  Ar(10) =  "examRelNote:Y"
  22.         '  Ar(11) =  "voyageFlightNo:1084-186S"
  23.         '  Ar(12) =  "marketMftNote:Y"
  24.         '  Ar(13) =  "status:ok"
  25.         '  Ar(14) =  "vslName:UNI-PROSPER"
½Æ»s¥N½X

TOP

  1. Sub TEST11()
  2.     Dim sID As String, sStatus As String
  3.     Dim x
  4.    
  5.     sID = InputBox("¥X¤f³ø³æ¸¹½X", "¥X¤f³ø³æ©ñ¦æ¸ê®Æ¬d¸ß", "BE  02XE580024")
  6.     If sID = "" Then Exit Sub
  7.    
  8.     With CreateObject("InternetExplorer.Application")
  9.         .Visible = True '¬O§_Åã¥ÜIE
  10.         .Navigate "http://portal.sw.nat.gov.tw/APGQ/GB315"
  11.         Do While .readyState <> 4: DoEvents: Loop
  12.       
  13.         Set x = .document.getElementById("myform").getElementsByTagName("input")
  14.         x(0).Value = sID  '¶ñ¤J¸¹½X
  15.         x(1).Click  '¬d¸ß
  16.         Do While .document.getElementById("statusMsg").Value = "": DoEvents: Loop
  17.       
  18.         sStatus = .document.getElementById("statusMsg").Value
  19.         If InStr(sStatus, "[°õ¦æ¦¨¥\]") < 0 Then .Quit: MsgBox sStatus: Exit Sub
  20.                        
  21.         .document.body.innerHTML = .document.getElementById("queryResult").outerHTML
  22.         .execwb 17, 2 'Select All
  23.         .execwb 12, 2 'Copy selection
  24.                
  25.         ActiveSheet.[A1].Select
  26.         ActiveSheet.PasteSpecial Format:="HTML" ', NoHTMLFormatting:=True
  27.         .Quit
  28.     End With
  29. End Sub
½Æ»s¥N½X

TOP

¦^´_ 18# stillfish00
  1. .document.body.innerHTML = .document.getElementById("queryResult").outerHTML
½Æ»s¥N½X
³o©Û¨ü±Ð¤F
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¥»©«³Ì«á¥Ñ joey0415 ©ó 2013-11-18 12:00 ½s¿è

¦^´_ 19# GBKEE
  1. .document.body.innerHTML = .document.getElementById("queryResult").outerHTML
½Æ»s¥N½X
§â.outerHTMLªº¶Çµ¹.body.innerHTML   ?

½Ð°Ý¶Wª©¡A³o¥y¸Ü«ç¸Ñ©O¡H

ÁÂÁÂ

TOP

        ÀR«ä¦Û¦b : ¸Ü¦h¤£¦p¸Ü¤Ö¡A¸Ü¤Ö¤£¦p¸Ü¦n¡C
ªð¦^¦Cªí ¤W¤@¥DÃD