{"id":3217,"date":"2012-02-28T12:55:52","date_gmt":"2012-02-27T18:55:52","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/3217"},"modified":"2012-02-28T12:59:15","modified_gmt":"2012-02-28T03:59:15","slug":"excel-vba-%e3%81%a7-jquery-%e3%81%ae%e3%82%88%e3%81%86%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%a7%e3%81%8d%e3%82%8b%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e3%82%92%e4%bd%9c%e3%82%8c","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/3217","title":{"rendered":"Excel VBA \u3067 jQuery \u306e\u3088\u3046\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u308c\u308b\u304b\uff1f"},"content":{"rendered":"<p>\u3061\u3063\u3068\u3070\u304b\u308a\u982d\u306e\u4f53\u64cd\u306e\u610f\u5473\u3082\u8fbc\u3081\u3066\u3001Excel VBA \u3092 jQuery \u98a8\u306b\u5f04\u308c\u308b\u304b\u3069\u3046\u304b\u306e\u30c6\u30b9\u30c8\u3092\u3002\u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001\u7d50\u69cb\u3044\u3051\u307e\u3059\u3002\u884c\u3051\u308b\u3093\u3058\u3083\u306a\u3044\u3060\u308d\u3046\u304b\uff1f\u306e\u6bb5\u968e\u307e\u3067\u306f\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>[code lang=&#8221;vb&#8221;]<br \/>\nOption Explicit<\/p>\n<p>&#8216; \u5ba3\u8a00<br \/>\nPrivate XL As New XLQuery<\/p>\n<p>Sub test001()<br \/>\n    XL.Cell(&quot;A1&quot;).Text = &quot;masuda&quot;<br \/>\n    XL.Cell(&quot;A1:A10&quot;).Text = &quot;masuda&quot;<br \/>\n    &#8216; \u884c\u5217\u6307\u5b9a<br \/>\n    XL.Cell(1, 2).Text = &quot;masuda&quot;<br \/>\n    &#8216; \u7bc4\u56f2\u6307\u5b9a<br \/>\n    XL.Cell(1, 2, 10, 2).Text = &quot;masuda&quot;<br \/>\n    &#8216; \u540d\u524d\u5b9a\u7fa9<br \/>\n    XL.Cell(&quot;#name&quot;).Text = &quot;masuda&quot;<br \/>\n    &#8216; \u30af\u30e9\u30b9\u5b9a\u7fa9\uff08\u5b9f\u306f\u540d\u524d\uff09<br \/>\n    XL.Cell(&quot;.name2&quot;).Text = &quot;masuda&quot;<br \/>\nEnd Sub<\/p>\n<p>Sub test002()<br \/>\n    &#8216; \u80cc\u666f\u8272\u3092\u8a2d\u5b9a<br \/>\n    XL.Cell(1, 1).css(&quot;background-color&quot;) = &quot;#FF0000&quot;<br \/>\n    &#8216; \u6587\u5b57\u8272\u3092\u8a2d\u5b9a<br \/>\n    XL.Cell(&quot;A2&quot;).css(&quot;color&quot;) = &quot;blue&quot;<br \/>\nEnd Sub<br \/>\n[\/code]<\/p>\n<p>\u306a\u98a8\u306a\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3068\u3001<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2012\/02\/wpid-dworkblogimage20120228_01org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2012\/02\/wpid-dworkblogimage20120228_01thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u306a\u4f4d\u307e\u3067\u306f\u3067\u304d\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u7df4\u7fd2\u30b3\u30fc\u30c9\u3082\u542b\u3081\u3066\u3042\u308b\u306e\u3067\u3001\u7121\u99c4\u304c\u591a\u3044\u3067\u3059\u304c\u3001\u3061\u3087\u3063\u3068\u5168\u30b3\u30fc\u30c9\u3092\u6652\u3057\u3066\u304a\u304d\u307e\u3059\uff57 \u4e8c\u3064\u306e\u30af\u30e9\u30b9\uff08XLQuery, XLRange\uff09\u3092\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>XLQuery \u30af\u30e9\u30b9<\/p>\n<p>[code lang=&#8221;vb&#8221;]<br \/>\nOption Explicit<br \/>\n&#8221;&#8217; excel vba query<\/p>\n<p>Private EmptyBook_ As Workbook<br \/>\nPrivate EmptySheet_ As Worksheet<br \/>\nPrivate Current_ As Worksheet<br \/>\nPrivate Selection_ As Range<\/p>\n<p>&#8221;&#8217; \u7c21\u6613\u30d7\u30ed\u30d1\u30c6\u30a3<br \/>\nPublic Property Get Application() As Excel.Application<br \/>\n    Applicaiton = Excel.Application<br \/>\nEnd Property<br \/>\nPublic Property Get Book() As Workbook<br \/>\n    Set Book = Excel.ActiveWorkbook<br \/>\nEnd Property<br \/>\nPublic Property Get Sheet() As Worksheet<br \/>\n    Set Sheet = Excel.ActiveSheet<br \/>\nEnd Property<\/p>\n<p>&#8221;&#8217; \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf<br \/>\nPublic Sub Class_Initialize()<br \/>\n    Set Current_ = Excel.ActiveSheet<br \/>\n    Set Selection_ = Excel.ActiveSheet.Cells(1, 1)<br \/>\nEnd Sub<\/p>\n<p>&#8221;&#8217; Empty \u30c1\u30a7\u30c3\u30af<br \/>\nPublic Property Get EmptySheet() As Worksheet<br \/>\n    Set EmptySheet = EmptySheet_<br \/>\nEnd Property<br \/>\nPublic Function IsEmptySheet(sh As Worksheet) As Boolean<br \/>\n   Set IsEmptySheet = IIf(sh = EmptySheet_, True, False)<br \/>\nEnd Function<\/p>\n<p>&#8221;&#8217; Worksheet \u3092\u53d6\u5f97<br \/>\nPublic Function GetSheet(name As String) As Worksheet<br \/>\n    Set GetSheet = EmptySheet_<br \/>\n    Dim sh As Worksheet<br \/>\n    For Each sh In Me.Book.Sheets<br \/>\n        If sh.name = name Then<br \/>\n            Set GetSheet = sh<br \/>\n            Exit For<br \/>\n        End If<br \/>\n    Next<br \/>\nEnd Function<\/p>\n<p>&#8221;&#8217; \u30ab\u30ec\u30f3\u30c8\u30b7\u30fc\u30c8\u306e\u8a2d\u5b9a\/\u53d6\u5f97<br \/>\nPublic Property Get Current() As Worksheet<br \/>\n    If Current_ Is Nothing Then<br \/>\n        Set Current = EmptySheet_<br \/>\n    Else<br \/>\n        Set Current = Current_<br \/>\n    End If<br \/>\nEnd Property<br \/>\nPublic Property Let Current(v As Worksheet)<br \/>\n    If v Is EmptySheet Then v = Nothing<br \/>\n    Set Current_ = v<br \/>\nEnd Property<\/p>\n<p>&#8221;&#8217; \u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\/\u8a2d\u5b9a<br \/>\nPublic Property Get Text() As String<br \/>\n    If Selection_ Is Nothing Then<br \/>\n        Text = &quot;&quot;<br \/>\n    ElseIf Selection_ Is Range Then<br \/>\n        Dim rg As Range<br \/>\n        Set rg = Selection_<br \/>\n        Text = rg.Text<\/p>\n<p>    Else<br \/>\n        Text = &quot;&quot;<br \/>\n    End If<br \/>\nEnd Property<br \/>\nPublic Property Let Text(Value As String)<br \/>\n    If Not Selection_ Is Nothing Then<br \/>\n        If TypeOf Selection_ Is Range Then<br \/>\n            Selection_.Value = Value<br \/>\n        End If<br \/>\n    End If<br \/>\nEnd Property<\/p>\n<p>&#8221;&#8217; \u30bb\u30eb\u306b\u30a2\u30af\u30bb\u30b9<br \/>\nPublic Function Cell(r1 As String, Optional c1 As String = &quot;&quot;, Optional r2 As String = &quot;&quot;, Optional c2 As String = &quot;&quot;) As XLRange<br \/>\n    Dim rg As New XLRange<br \/>\n    &#8216; Cell(&quot;A1&quot;)\u547c\u51fa<br \/>\n    &#8216; Cell(&quot;A1:B10&quot;)\u547c\u51fa<br \/>\n    &#8216; Cell(&quot;#id&quot;)\u547c\u51fa<br \/>\n    &#8216; Cell(&quot;.class&quot;)\u547c\u51fa<br \/>\n    If c1 = &quot;&quot; Then<br \/>\n        If Left(r1, 1) = &quot;#&quot; Then<br \/>\n            rg.self = Me.Sheet.Range(Mid(r1, 2))<br \/>\n        ElseIf Left(r1, 1) = &quot;.&quot; Then<br \/>\n            rg.self = Me.Sheet.Range(Mid(r1, 2))<br \/>\n        Else<br \/>\n             rg.self = Me.Sheet.Range(r1)<br \/>\n        End If<br \/>\n    &#8216; Cell(1,1)\u547c\u51fa<br \/>\n    ElseIf r2 = &quot;&quot; Then<br \/>\n        rg.self = Me.Sheet.Cells(CInt(r1), CInt(c1))<br \/>\n    &#8216; Cell(1,1,2,10)\u547c\u51fa<br \/>\n    Else<br \/>\n        rg.self = Me.Sheet.Range(Me.Sheet.Cells(CInt(r1), CInt(c1)), Me.Sheet.Cells(CInt(r2), CInt(c2)))<br \/>\n    End If<br \/>\n    Set Cell = rg<br \/>\nEnd Function<br \/>\n[\/code]<\/p>\n<p>XLRange \u30af\u30e9\u30b9<\/p>\n<p>[code lang=&#8221;vb&#8221;]<br \/>\nOption Explicit<br \/>\nPrivate text_ As String<br \/>\nPrivate range_ As Range<\/p>\n<p>Public Property Get Text() As String<br \/>\n    Text = text_<br \/>\nEnd Property<br \/>\nPublic Property Let Text(v As String)<br \/>\n    text_ = v<br \/>\n    If Me.self Is Nothing Then Exit Property<br \/>\n    Me.self.Value = v<br \/>\nEnd Property<\/p>\n<p>Public Property Get self() As Range<br \/>\n    Set self = range_<br \/>\nEnd Property<br \/>\nPublic Property Let self(v As Range)<br \/>\n    Set range_ = v<br \/>\nEnd Property<\/p>\n<p>Public Property Let css(prop As String, v As String)<br \/>\n    If Me.self Is Nothing Then Exit Property<br \/>\n    Select Case StrConv(prop, vbLowerCase)<br \/>\n    Case &quot;background-color&quot;: self.Interior.Color = toRGB(v)<br \/>\n    Case &quot;color&quot;: self.Font.Color = toRGB(v)<br \/>\n    End Select<br \/>\nEnd Property<\/p>\n<p>Private Function toRGB(v As String)<br \/>\n    If Left(v, 1) = &quot;#&quot; Then<br \/>\n        Dim r, g, b<br \/>\n        r = CInt(&quot;&amp;H&quot; + Mid(v, 2, 2))<br \/>\n        g = CInt(&quot;&amp;H&quot; + Mid(v, 4, 2))<br \/>\n        b = CInt(&quot;&amp;H&quot; + Mid(v, 6, 2))<br \/>\n        toRGB = RGB(r, g, b)<br \/>\n    Else<br \/>\n        Select Case v<br \/>\n        Case &quot;red&quot;: toRGB = RGB(255, 0, 0)<br \/>\n        Case &quot;blue&quot;: toRGB = RGB(0, 0, 255)<br \/>\n        Case &quot;green&quot;: toRGB = RGB(0, 255, 0)<br \/>\n\t\t&#8216; \u3053\u306e\u3042\u305f\u308a\u306f\u5f8c\u3067<br \/>\n        End Select<br \/>\n    End If<br \/>\nEnd Function<br \/>\n[\/code]<\/p>\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u7701\u7565\uff08option\uff09\u3092\u99c6\u4f7f\u3057\u3066\u3001\u305d\u308c\u98a8\u306b\u52d5\u304f\u3088\u3046\u306b\u3057\u307e\u3059\u3002VBA \u306e\u5236\u9650\u3068\u3057\u3066\u30af\u30e9\u30b9\u3092\u3072\u3068\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u8907\u6570\u306e\u30af\u30e9\u30b9\u3092\u7f6e\u3051\u306a\u3044\u306e\u3067\u3001\u5229\u7528\u3059\u308b\u5074\u3092\u8003\u616e\u3057\u3066\u30af\u30e9\u30b9\u306f\u591a\u304f\u306a\u3044\u69d8\u306b\u3057\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u7d99\u627f\u306a\u3069\u672c\u6765\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u306f\u7121\u8996\u3057\u3066\uff08\u82e6\u7b11\uff09\u3001\u4f7f\u3044\u3084\u3059\u3044\u5f62\u3067\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u306e\u90e8\u5206\u3060\u3051\u6b8b\u3057\u3066\u304a\u304f\u3068\u3044\u3046\u3053\u3068\u3067\u3002<br \/>\nXLRange \u30af\u30e9\u30b9\u306e css \u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u3063\u3066\u3001\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u98a8\u306b\u8a2d\u5b9a\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308c\u3070\u3001Excel \u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u899a\u3048\u306a\u304f\u3066\u826f\u3044\u306e\u3067\u3001\u305d\u306e\u70b9\u306f\u697d\u304b\u306a\u3068\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3061\u3063\u3068\u3070\u304b\u308a\u982d\u306e\u4f53\u64cd\u306e\u610f\u5473\u3082\u8fbc\u3081\u3066\u3001Excel VBA \u3092 jQuery \u98a8\u306b\u5f04\u308c\u308b\u304b\u3069\u3046\u304b\u306e\u30c6\u30b9\u30c8\u3092\u3002\u7d50\u8ad6\u304b\u3089\u8a00\u3048\u3070\u3001\u7d50\u69cb\u3044\u3051\u307e\u3059\u3002\u884c\u3051\u308b\u3093\u3058\u3083\u306a\u3044\u3060\u308d\u3046\u304b\uff1f\u306e\u6bb5\u968e\u307e\u3067\u306f\u3067\u304d\u307e\u3057\u305f\u3002 [code lang=&#038;#8221 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/3217\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[5,42],"tags":[],"class_list":["post-3217","post","type-post","status-publish","format-standard","hentry","category-etc","category-excel-vba"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=3217"}],"version-history":[{"count":4,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3217\/revisions"}],"predecessor-version":[{"id":3220,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3217\/revisions\/3220"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=3217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=3217"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=3217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}