{"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<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\n\r\n' \u5ba3\u8a00\r\nPrivate XL As New XLQuery\r\n\r\nSub test001()\r\n    XL.Cell(&quot;A1&quot;).Text = &quot;masuda&quot;\r\n    XL.Cell(&quot;A1:A10&quot;).Text = &quot;masuda&quot;\r\n    ' \u884c\u5217\u6307\u5b9a\r\n    XL.Cell(1, 2).Text = &quot;masuda&quot;\r\n    ' \u7bc4\u56f2\u6307\u5b9a\r\n    XL.Cell(1, 2, 10, 2).Text = &quot;masuda&quot;\r\n    ' \u540d\u524d\u5b9a\u7fa9\r\n    XL.Cell(&quot;#name&quot;).Text = &quot;masuda&quot;\r\n    ' \u30af\u30e9\u30b9\u5b9a\u7fa9\uff08\u5b9f\u306f\u540d\u524d\uff09\r\n    XL.Cell(&quot;.name2&quot;).Text = &quot;masuda&quot;\r\nEnd Sub\r\n\r\nSub test002()\r\n    ' \u80cc\u666f\u8272\u3092\u8a2d\u5b9a\r\n    XL.Cell(1, 1).css(&quot;background-color&quot;) = &quot;#FF0000&quot;\r\n    ' \u6587\u5b57\u8272\u3092\u8a2d\u5b9a\r\n    XL.Cell(&quot;A2&quot;).css(&quot;color&quot;) = &quot;blue&quot;\r\nEnd Sub\r\n<\/pre>\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<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\n''' excel vba query\r\n\r\nPrivate EmptyBook_ As Workbook\r\nPrivate EmptySheet_ As Worksheet\r\nPrivate Current_ As Worksheet\r\nPrivate Selection_ As Range\r\n\r\n''' \u7c21\u6613\u30d7\u30ed\u30d1\u30c6\u30a3\r\nPublic Property Get Application() As Excel.Application\r\n    Applicaiton = Excel.Application\r\nEnd Property\r\nPublic Property Get Book() As Workbook\r\n    Set Book = Excel.ActiveWorkbook\r\nEnd Property\r\nPublic Property Get Sheet() As Worksheet\r\n    Set Sheet = Excel.ActiveSheet\r\nEnd Property\r\n\r\n''' \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\nPublic Sub Class_Initialize()\r\n    Set Current_ = Excel.ActiveSheet\r\n    Set Selection_ = Excel.ActiveSheet.Cells(1, 1)\r\nEnd Sub\r\n\r\n''' Empty \u30c1\u30a7\u30c3\u30af\r\nPublic Property Get EmptySheet() As Worksheet\r\n    Set EmptySheet = EmptySheet_\r\nEnd Property\r\nPublic Function IsEmptySheet(sh As Worksheet) As Boolean\r\n   Set IsEmptySheet = IIf(sh = EmptySheet_, True, False)\r\nEnd Function\r\n\r\n''' Worksheet \u3092\u53d6\u5f97\r\nPublic Function GetSheet(name As String) As Worksheet\r\n    Set GetSheet = EmptySheet_\r\n    Dim sh As Worksheet\r\n    For Each sh In Me.Book.Sheets\r\n        If sh.name = name Then\r\n            Set GetSheet = sh\r\n            Exit For\r\n        End If\r\n    Next\r\nEnd Function\r\n\r\n''' \u30ab\u30ec\u30f3\u30c8\u30b7\u30fc\u30c8\u306e\u8a2d\u5b9a\/\u53d6\u5f97\r\nPublic Property Get Current() As Worksheet\r\n    If Current_ Is Nothing Then\r\n        Set Current = EmptySheet_\r\n    Else\r\n        Set Current = Current_\r\n    End If\r\nEnd Property\r\nPublic Property Let Current(v As Worksheet)\r\n    If v Is EmptySheet Then v = Nothing\r\n    Set Current_ = v\r\nEnd Property\r\n\r\n''' \u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\/\u8a2d\u5b9a\r\nPublic Property Get Text() As String\r\n    If Selection_ Is Nothing Then\r\n        Text = &quot;&quot;\r\n    ElseIf Selection_ Is Range Then\r\n        Dim rg As Range\r\n        Set rg = Selection_\r\n        Text = rg.Text\r\n\r\n    Else\r\n        Text = &quot;&quot;\r\n    End If\r\nEnd Property\r\nPublic Property Let Text(Value As String)\r\n    If Not Selection_ Is Nothing Then\r\n        If TypeOf Selection_ Is Range Then\r\n            Selection_.Value = Value\r\n        End If\r\n    End If\r\nEnd Property\r\n\r\n''' \u30bb\u30eb\u306b\u30a2\u30af\u30bb\u30b9\r\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\r\n    Dim rg As New XLRange\r\n    ' Cell(&quot;A1&quot;)\u547c\u51fa\r\n    ' Cell(&quot;A1:B10&quot;)\u547c\u51fa\r\n    ' Cell(&quot;#id&quot;)\u547c\u51fa\r\n    ' Cell(&quot;.class&quot;)\u547c\u51fa\r\n    If c1 = &quot;&quot; Then\r\n        If Left(r1, 1) = &quot;#&quot; Then\r\n            rg.self = Me.Sheet.Range(Mid(r1, 2))\r\n        ElseIf Left(r1, 1) = &quot;.&quot; Then\r\n            rg.self = Me.Sheet.Range(Mid(r1, 2))\r\n        Else\r\n             rg.self = Me.Sheet.Range(r1)\r\n        End If\r\n    ' Cell(1,1)\u547c\u51fa\r\n    ElseIf r2 = &quot;&quot; Then\r\n        rg.self = Me.Sheet.Cells(CInt(r1), CInt(c1))\r\n    ' Cell(1,1,2,10)\u547c\u51fa\r\n    Else\r\n        rg.self = Me.Sheet.Range(Me.Sheet.Cells(CInt(r1), CInt(c1)), Me.Sheet.Cells(CInt(r2), CInt(c2)))\r\n    End If\r\n    Set Cell = rg\r\nEnd Function\r\n<\/pre>\n<p>XLRange \u30af\u30e9\u30b9<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Explicit\r\nPrivate text_ As String\r\nPrivate range_ As Range\r\n\r\nPublic Property Get Text() As String\r\n    Text = text_\r\nEnd Property\r\nPublic Property Let Text(v As String)\r\n    text_ = v\r\n    If Me.self Is Nothing Then Exit Property\r\n    Me.self.Value = v\r\nEnd Property\r\n\r\nPublic Property Get self() As Range\r\n    Set self = range_\r\nEnd Property\r\nPublic Property Let self(v As Range)\r\n    Set range_ = v\r\nEnd Property\r\n\r\nPublic Property Let css(prop As String, v As String)\r\n    If Me.self Is Nothing Then Exit Property\r\n    Select Case StrConv(prop, vbLowerCase)\r\n    Case &quot;background-color&quot;: self.Interior.Color = toRGB(v)\r\n    Case &quot;color&quot;: self.Font.Color = toRGB(v)\r\n    End Select\r\nEnd Property\r\n\r\nPrivate Function toRGB(v As String)\r\n    If Left(v, 1) = &quot;#&quot; Then\r\n        Dim r, g, b\r\n        r = CInt(&quot;&H&quot; + Mid(v, 2, 2))\r\n        g = CInt(&quot;&H&quot; + Mid(v, 4, 2))\r\n        b = CInt(&quot;&H&quot; + Mid(v, 6, 2))\r\n        toRGB = RGB(r, g, b)\r\n    Else\r\n        Select Case v\r\n        Case &quot;red&quot;: toRGB = RGB(255, 0, 0)\r\n        Case &quot;blue&quot;: toRGB = RGB(0, 0, 255)\r\n        Case &quot;green&quot;: toRGB = RGB(0, 255, 0)\r\n\t\t' \u3053\u306e\u3042\u305f\u308a\u306f\u5f8c\u3067\r\n        End Select\r\n    End If\r\nEnd Function\r\n<\/pre>\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 Option Explicit &#8216; &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_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,42],"tags":[],"class_list":["post-3217","post","type-post","status-publish","format-standard","hentry","category-etc","category-excel-vba"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_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}]}}