{"id":10220,"date":"2022-05-11T10:59:03","date_gmt":"2022-05-11T17:59:03","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=10220"},"modified":"2022-05-25T14:45:50","modified_gmt":"2022-05-25T21:45:50","slug":"office-javascript-api-for-power-query-read-only-data-now-available-for-excel","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/office-javascript-api-for-power-query-read-only-data-now-available-for-excel\/","title":{"rendered":"Office JavaScript API for Power Query read-only data now available for Excel"},"content":{"rendered":"<p>The new Office JavaScript API for Power Query read-only data endpoint is designated for Excel and aligns with our vision of creating a familiar, robust cross-platform user experience.\nThese APIs allow you to retrieve data related to Power Query queries you have in your Excel workbooks.<\/p>\n<h2>Code samples: Use Office JavaScript API for Power Query<\/h2>\n<p>Here are two examples of how you can use the new Office JS APIs for Excel.<\/p>\n<p>1. If you want to see the query parameters <strong>name<\/strong>, <strong>last refresh date<\/strong>,\nand <strong>rows loaded count<\/strong>, call the API as shown in the following code sample.<\/p>\n<pre class=\"prettyprint\"><code class=\"language-javascript\">\r\nasync function run() {\r\n    await Excel.run(async (context) =&gt; {\r\n        const queries = context.workbook.queries;\r\n        queries.load(\"items\");\r\n        await context.sync();\r\n        console.log(\"rows loaded: \" + queries.items.map((q) =&gt; q.rowsLoadedCount));\r\n        console.log(\"last refresh dates: \" + queries.items.map((q) =&gt; q.refreshDate));\r\n    });\r\n}\r\n<\/code><\/pre>\n<p>2. You can also count all of the queries in the workbook. For example, you can call the following Excel API.<\/p>\n<pre class=\"prettyprint\">const count = queries.getCount();<\/pre>\n<p>For more details, see the documentation for <a href=\"https:\/\/docs.microsoft.com\/javascript\/api\/excel\/excel.query?view=excel-js-preview\">Excel.Query class<\/a> and <a href=\"https:\/\/docs.microsoft.com\/javascript\/api\/excel\/excel.querycollection?view=excel-js-preview\">Excel.QueryCollection class<\/a>.<\/p>\n<h3>What\u2019s Next in Office JavaScript API for Excel?<\/h3>\n<p>We\u2019re looking into adding more Power Query capabilities via Office JavaScript APIs, such as refreshing queries and editing them.<\/p>\n<p>We encourage you to try out this API as we continue to work towards improving user productivity. For any feedback, suggestions, or questions on the API, let us know by leaving a comment, or using the Feedback button in the top corner in Excel &#8211; add #PowerQuery in your feedback so that we can find it easily.<\/p>\n<h3>More Excel development resources<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/javascript\/api\/excel?view=excel-js-preview\">Excel JavaScript API preview<\/a><\/li>\n<li><a href=\"https:\/\/developer.microsoft.com\/excel\">Excel Developer Center<\/a><\/li>\n<li>Read blog: <a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/announcing-changes-to-office-add-ins-executefunction-commands\/\">Changes to Excel API ExecuteFunction commands<\/a><\/li>\n<li>Read article: <a href=\"https:\/\/docs.microsoft.com\/en-us\/office\/dev\/scripts\/resources\/power-query-differences\">When to use Power Query or Office Scripts<\/a><\/li>\n<\/ul>\n<p>Happy coding!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>New Office JavaScript APIs allow you to retrieve data related to Power Query queries you have in your Excel workbooks.<\/p>\n","protected":false},"author":87670,"featured_media":10223,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[18,168],"class_list":["post-10220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-add-ins","tag-excel","tag-office-javascript-api"],"acf":[],"blog_post_summary":"<p>New Office JavaScript APIs allow you to retrieve data related to Power Query queries you have in your Excel workbooks.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/10220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/87670"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=10220"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/10220\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/10223"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=10220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=10220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=10220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}