{"id":7236,"date":"2016-08-23T10:17:56","date_gmt":"2016-08-23T01:17:56","guid":{"rendered":"https:\/\/www.ka-net.org\/blog\/?p=7236"},"modified":"2016-10-25T22:07:50","modified_gmt":"2016-10-25T13:07:50","slug":"excel-rest-api%e3%82%92powershell%e3%81%8b%e3%82%89%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%99%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.ka-net.org\/blog\/?p=7236","title":{"rendered":"Excel REST API\u3092PowerShell\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5"},"content":{"rendered":"<p>\u4ee5\u524dExcel REST API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c(\u4e0b\u8a18\u8a18\u4e8b\u53c2\u7167)\u3001\u305d\u306e\u3068\u304d\u306f\u307e\u3060API\u304c\u30d9\u30fc\u30bf\u7248\u3067\u3057\u305f\u3002<\/p>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=6874\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Excel-120x120.png' alt='Excel REST API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2016.03.31<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=6874\">Excel REST API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5 <\/a><\/div><div class=\"cardlink_excerpt\">\u300cMicrosoft Graph\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3057\u3066OneNote\u306e\u30da\u30fc\u30b8\u5185\u5bb9\u3092\u53d6\u5f97\u3059\u308b\u300d\u8a18\u4e8b\u3067\u89e6\u308c\u3066\u3044\u305f\u201cExcel REST API\u201d\u3067\u3059\u304c\u3001\u77e5\u3089\u306c\u9593\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u305f\u307f\u305f\u3044\u3067\u3059\u3002\r\n\r\n\r\n\u305d\u308c\u306a\u3089\u3070\u3084\u308b\u3053\u3068\u306f\u4e00\u3064\u3002\r\nVBA\u304b\u3089\u547c\u3073\u51fa\u3057\u3066\u307f\u305f\u3044...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n<p>\u4eca\u6708\u521d\u3081\u306b\u3088\u3046\u3084\u304f<a href=\"https:\/\/blogs.technet.microsoft.com\/mpn_japan\/2016\/08\/16\/announcing-the-general-availability-of-the-microsoft-excel-api-to-expand-the-power-of-office-365\/\" title=\"Microsoft Excel API \u304c\u4e00\u822c\u63d0\u4f9b\u958b\u59cb\u3055\u308c Office 365 \u304c\u3088\u308a\u30d1\u30ef\u30d5\u30eb\u306b\u306a\u308a\u307e\u3057\u305f\u30108\/16 \u66f4\u65b0\u3011 - Microsoft Partner Network \u30d6\u30ed\u30b0\" target=\"_blank\">\u6b63\u5f0f\u7248\u304c\u30ea\u30ea\u30fc\u30b9<\/a>\u3055\u308c\u305f\u306e\u3067\u3001\u4eca\u56de\u306f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305f\u3070\u304b\u308a\u306eAPI\u3092PowerShell\u304b\u3089\u547c\u3073\u51fa\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h4 class=\"style4a\">\u4e0b\u6e96\u5099<\/h4>\n<p>API\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306bAzure AD\u306e\u8a2d\u5b9a\u3084\u3089\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID\u306e\u53d6\u5f97\u3084\u3089\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u7d30\u304b\u3044\u8aac\u660e\u306f\u3053\u3053\u3067\u306f\u5272\u611b\u3057\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u8a18\u4e8b\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"cardlink\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=5620\"><div class=\"cardlink_thumbnail\"><img src='https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Office365-120x120.png' alt='Office 365 unified API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059' width=120 height=120 \/><\/a><\/div><div class=\"cardlink_content\"><span class=\"timestamp\">2015.05.22<\/span><div class=\"cardlink_title\"><a href=\"https:\/\/www.ka-net.org\/blog\/?p=5620\">Office 365 unified API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059 <\/a><\/div><div class=\"cardlink_excerpt\">\u524d\u56de\u306e\u8a18\u4e8b\u3067\u3001VBA\u304b\u3089Office 365 API\u3092\u547c\u3073\u51fa\u3059\u624b\u9806\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u307e\u3057\u305f\u3002\r\nOAuth 2.0 \u8a8d\u8a3c + REST\u3068\u3044\u3046\u4e00\u822c\u7684\u306a\u65b9\u5f0f\u3067\u3001\u8a00\u8a9e\u74b0\u5883\u3092\u9078\u3070\u305a\u624b\u8efd\u306b\u5916\u90e8\u304b\u3089Office 365\u306e\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3001\u3068\u3066\u3082\u4fbf\u5229\u306aAPI\u3067\u3059\u3002\r\n...<\/div><\/div><div class=\"cardlink_footer\"><\/div><\/div>\n<ol>\n<li>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7a2e\u985e\uff1a\u30cd\u30a4\u30c6\u30a3\u30d6 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3<\/li>\n<li>\u30ea\u30c0\u30a4\u30ec\u30af\u30c8 URI\uff1ahttp:\/\/localhost\/ERASample<\/li>\n<li>\u4ed6\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5bfe\u3059\u308b\u30a2\u30af\u30bb\u30b9\u8a31\u53ef\uff1aMicrosoft Graph<\/li>\n<li>\u30c7\u30ea\u30b2\u30fc\u30c8\u3055\u308c\u305f\u30a2\u30af\u30bb\u30b9\u8a31\u53ef\uff1aHave full access to user files<\/li>\n<\/ol>\n<h4 class=\"style4a\">PowerShell\u30b3\u30fc\u30c9<\/h4>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">#Using PowerShell and the Office 365 REST API with OAuth.\r\n#https:\/\/blogs.technet.microsoft.com\/ronba\/2016\/05\/09\/using-powershell-and-the-office-365-rest-api-with-oauth\/\r\nFunction Show-OAuthWindow\r\n{\r\n  param(\r\n    &#x5B;System.Uri]$Url\r\n  )\r\n  \r\n  Add-Type -AssemblyName System.Windows.Forms\r\n\r\n  $form = New-Object -TypeName System.Windows.Forms.Form -Property @{Width=440;Height=640}\r\n  $web  = New-Object -TypeName System.Windows.Forms.WebBrowser -Property @{Width=420;Height=600;Url=($url)}\r\n  $DocComp  = {\r\n    $Global:uri = $web.Url.AbsoluteUri\r\n    if($Global:Uri -match &quot;error=&#x5B;^&amp;]*|code=&#x5B;^&amp;]*&quot;){$form.Close()}\r\n  }\r\n  $web.ScriptErrorsSuppressed = $true\r\n  $web.Add_DocumentCompleted($DocComp)\r\n  $form.Controls.Add($web)\r\n  $form.Add_Shown({$form.Activate()})\r\n  $form.ShowDialog() | Out-Null\r\n\r\n  $queryOutput = &#x5B;System.Web.HttpUtility]::ParseQueryString($web.Url.Query)\r\n  $output = @{}\r\n  foreach($key in $queryOutput.Keys){\r\n    $output&#x5B;&quot;$key&quot;] = $queryOutput&#x5B;$key]\r\n  }\r\n\r\n  $output\r\n}\r\n\r\n#------------------------------\r\n# \u8981\u5909\u66f4\r\n#------------------------------\r\n$client_id = &quot;(\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 ID)&quot;\r\n$redirectUrl = &quot;http:\/\/localhost\/ERASample&quot;\r\n$targetFile = &quot;SampleBook.xlsx&quot;\r\n$targetSheet = &quot;SampleSheet&quot;\r\n#------------------------------\r\n\r\n#authorization code\u53d6\u5f97\r\nAdd-Type -AssemblyName System.Web\r\n$loginUrl = &quot;https:\/\/login.microsoftonline.com\/common\/oauth2\/authorize?response_type=code&amp;redirect_uri=&quot; +\r\n            &#x5B;System.Web.HttpUtility]::UrlEncode($redirectUrl) + \r\n            &quot;&amp;client_id=$client_id&quot;\r\n$queryOutput = Show-OAuthWindow -Url $loginUrl\r\n\r\n#access token\u53d6\u5f97\r\n$AuthorizationPostRequest = \r\n  &quot;grant_type=authorization_code&quot; + &quot;&amp;&quot; +\r\n  &quot;redirect_uri=&quot; + &#x5B;System.Web.HttpUtility]::UrlEncode($redirectUrl) + &quot;&amp;&quot; +\r\n  &quot;client_id=$client_id&quot; + &quot;&amp;&quot; +\r\n  &quot;code=&quot; + $queryOutput&#x5B;&quot;code&quot;] + &quot;&amp;&quot; +\r\n  &quot;resource=&quot; + &#x5B;System.Web.HttpUtility]::UrlEncode(&quot;https:\/\/graph.microsoft.com\/&quot;)\r\n$Authorization = \r\n  Invoke-RestMethod -Method Post `\r\n                    -ContentType application\/x-www-form-urlencoded `\r\n                    -Uri https:\/\/login.microsoftonline.com\/common\/oauth2\/token `\r\n                    -Body $AuthorizationPostRequest\r\n\r\n#OneDrive\u306e\u30d5\u30a1\u30a4\u30eb\u5217\u6319\r\n#\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u3066\u30d5\u30a1\u30a4\u30ebID\u53d6\u5f97\r\n$items = \r\n  Invoke-RestMethod -Method Get `\r\n                    -Headers @{Authorization = (&quot;Bearer &quot;+ $Authorization.access_token)} `\r\n                    -Uri https:\/\/graph.microsoft.com\/v1.0\/me\/drive\/root\/children\r\n$items.value | ForEach-Object{\r\n  if($_.name -eq $targetFile){\r\n    $fileId = $_.id\r\n  }\r\n}\r\n\r\n#\u6307\u5b9a\u3057\u305f\u30ef\u30fc\u30af\u30b7\u30fc\u30c8\u306e\u30bb\u30ebC2\u306e\u5024\u3092\u53d6\u5f97\r\n$apiUrl = &quot;https:\/\/graph.microsoft.com\/v1.0\/me\/drive\/items\/$fileId\/workbook\/worksheets\/$targetSheet\/Range(address='C2')&quot;\r\n$rng = \r\n  Invoke-RestMethod -Method Get `\r\n  -Headers @{Authorization = (&quot;Bearer &quot;+ $Authorization.access_token)} `\r\n  -Uri $apiUrl\r\nWrite-Host $rng.values<\/pre>\n<p>\u4e0a\u8a18\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001Office 365\u306e\u30b5\u30a4\u30f3\u30a4\u30f3\u753b\u9762\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_01.jpg\" alt=\"ExcelRestAPI_PowerShell_01\" width=\"1136\" height=\"866\" class=\"alignnone size-full wp-image-7237\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_01.jpg 1136w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_01-300x229.jpg 300w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_01-768x585.jpg 768w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_01-1024x781.jpg 1024w\" sizes=\"auto, (max-width: 1136px) 100vw, 1136px\" \/><\/p>\n<p>\u8a8d\u8a3c\u5f8c\u3001\u554f\u984c\u306a\u304fAPI\u306e\u547c\u3073\u51fa\u3057\u304c\u884c\u308f\u308c\u308b\u3068\u3001\u6307\u5b9a\u3057\u305f\u30bb\u30eb\u306e\u5024\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_02.jpg\" alt=\"ExcelRestAPI_PowerShell_02\" width=\"514\" height=\"198\" class=\"alignnone size-full wp-image-7238\" srcset=\"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_02.jpg 514w, https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/ExcelRestAPI_PowerShell_02-300x116.jpg 300w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><\/p>\n<h4 class=\"style4a\">\u304a\u308f\u308a\u306b<\/h4>\n<p>\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u306f\u3001\u5b9f\u306f\u300c<a href=\"https:\/\/blogs.technet.microsoft.com\/ronba\/2016\/05\/09\/using-powershell-and-the-office-365-rest-api-with-oauth\/\" title=\"Using PowerShell and the Office 365 REST API with OAuth. - Ron Ben Artzi\" target=\"_blank\">Using PowerShell and the Office 365 REST API with OAuth. &#8211; Ron Ben Artzi<\/a>\u300d\u306e\u30b3\u30fc\u30c9\u3092\u307b\u307c\u305d\u306e\u307e\u307e\u6301\u3063\u3066\u304d\u305f\u3060\u3051\u306a\u306e\u3067\u3059\u304c\u3001\u601d\u3063\u305f\u4ee5\u4e0a\u306b\u30b7\u30f3\u30d7\u30eb\u306b\u66f8\u3051\u3066\u30d3\u30c3\u30af\u30ea\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>WebBrowser\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3092\u914d\u7f6e\u3057\u305fWindows \u30d5\u30a9\u30fc\u30e0\u3092\u52d5\u7684\u306b\u4f5c\u6210\u3059\u308b\u3053\u306e\u65b9\u6cd5\u3001\u306a\u304b\u306a\u304b\u4f7f\u3044\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/technet.microsoft.com\/ja-jp\/library\/hh849971.aspx\" title=\"Invoke-RestMethod\" target=\"_blank\">Invoke-RestMethod<\/a>\u30b3\u30de\u30f3\u30c9\u3082\u4fbf\u5229\u3067\u3059\u306d\uff01<br \/>\nPowerShell 3.0\u4ee5\u964d\u3067\u306a\u3044\u3068\u4f7f\u3048\u307e\u305b\u3093\u304c\u3001\u7c21\u5358\u306bWeb API\u306e\u547c\u3073\u51fa\u3057\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>VBA\u306b\u6bd4\u3079\u308b\u3068\u3060\u3044\u3076\u77ed\u304f\u30b3\u30fc\u30c9\u304c\u66f8\u3051\u308b\u306e\u3067\u3001\u3061\u3087\u3063\u3068API\u3092\u8a66\u3057\u305f\u3044\u3068\u304d\u306f\u4fbf\u5229\u3060\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4f7f\u3044\u3084\u3059\u3055\u3067\u3044\u3046\u3068\u300c<a href=\"https:\/\/graph.microsoft.io\/ja-jp\/graph-explorer\" title=\"Microsoft Graph - Graph Explorer\" target=\"_blank\">Graph Explorer<\/a>\u300d\u306b\u306f\u9060\u304f\u53ca\u3073\u307e\u305b\u3093\u3002<br \/>\n<span style=\"color: #ff0000; font-weight: bold;\">\u201cPowerShell\u3067\u3082Excel REST API\u547c\u3079\u308b\u3093\u3060\u30fc\uff01\u201d<\/span>\u7684\u306b\u601d\u3063\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4ee5\u524dExcel REST API\u3092VBA\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c(\u4e0b\u8a18\u8a18\u4e8b\u53c2\u7167)\u3001\u305d\u306e\u3068\u304d\u306f\u307e\u3060API\u304c\u30d9\u30fc\u30bf\u7248\u3067\u3057\u305f\u3002 \u4eca\u6708\u521d\u3081\u306b\u3088\u3046\u3084\u304f\u6b63\u5f0f\u7248\u304c\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305f\u306e\u3067\u3001\u4eca\u56de\u306f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305f\u3070\u304b\u308a\u306eAPI\u3092Powe [&hellip;]","protected":false},"author":1,"featured_media":7118,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"[Excel REST API\u3092PowerShell\u304b\u3089\u547c\u3073\u51fa\u3059\u65b9\u6cd5]","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,48,94,147,112],"tags":[],"class_list":["post-7236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office","category-excel-office","category-powershell","category-microsoft-graph","category-office365"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.ka-net.org\/blog\/wp-content\/uploads\/eyecatch-Office365.png","jetpack_shortlink":"https:\/\/wp.me\/p4UZZr-1SI","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7236"}],"version-history":[{"count":1,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7236\/revisions"}],"predecessor-version":[{"id":7239,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7236\/revisions\/7239"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=\/wp\/v2\/media\/7118"}],"wp:attachment":[{"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ka-net.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}