在 Excel Services REST API 中发现

上次修改时间: 2010年4月14日

适用范围: SharePoint Server 2010

本主题讨论 Excel Services REST API 中内置的发现机制。

发现基 URL 和发现示例

利用发现,开发人员和用户可手动或以编程方式发现有关工作簿的信息及其内容。发现机制提供了 Atom(该链接可能指向英文页面) 源,其中包含有关工作簿中资源的信息。通过使用发现,可以浏览和查看工作簿中的资源。可浏览和访问的资源为区域、图表、表和数据透视表。

以下是工作簿中特定元素的 REST URL 的构造:

http://<ServerName>/_vti_bin/ExcelRest.aspx/<DocumentLibrary>/<FileName>/<ResourceLocation>

基本 URI 结构和路径主题中所述,以下是一个 REST URL,用于访问名为"sampleWorkbook.xlsx"的工作簿和进一步查看名为"SampleChart"的图表:

http://<ServerName>/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('SampleChart')

若要使用发现来启动和浏览工作簿中的资源以及查看这些资源,请使用紧跟此示例之后的 URI 转到模型页:

http://<ServerName>/_vti_bin/ExcelRest.aspx/<DocumentLibrary>/<FileName>/model

使用"sampleWorkbook.xlsx"示例,以下是 URI:

http://<ServerName>/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model

以下是模型页的屏幕快照。

Excel Services REST 模型 URL

Excel Services REST 模型 URL

模型页的 URL 是用于启动发现的位置。模型页会显示 Excel Services REST API 当前支持的四个资源集。这些资源集是区域、图表、表或数据透视表。可通过单击模型页上的"区域"、"图表"、"表"或"数据透视表"在特定工作簿中浏览这些资源。

例如,若要使用发现来访问工作簿中的图表,请执行以下操作:

  1. 在模型页上单击"图表"。单击"图表"链接会显示另一个 Atom 源,此结果源将列出 sampleWorkbook.xlsx 工作簿中可用的所有图表。sampleWorkbook.xlsx 工作簿包含三个图表,它们分别名为"Chart 1"、"Chart 3"和"SampleChart"。因此将列出三个图表名称,如以下屏幕快照所示。

    Excel Services REST 发现图表列表

  2. 在模型页上单击"SampleChart"。这将显示位于"sampleWorkbook.xlsx"中的名为"SampleChart"的图表,如以下屏幕快照所示。

    使用 REST 查看图表

    使用 REST 查看图表

  3. 同样,单击"Chart 1"或"Chart 3"可显示具有相应名称的图表。单击"SampleChart"会导航到实际图表 URL。以下是"SampleChart"图像的 URL(如屏幕快照中所示):

    http://<ServerName>/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('SampleChart%20')?$format=image
    

Atom 源

利用 REST API 提供的 Atom(该链接可能指向英文页面) 源,可以更轻松地获取感兴趣的数据。如果查看网页的源,则获取 XML。以下显示的是"sampleWorkbook.xlsx"的图表中的示例。

如 XML 中所示,该源包含可遍历的元素,从而使代码能够发现工作簿中存在的元素。每个 Atom 项均对应于一个可访问的图表。此机制也适用于发现区域、表和数据透视表。

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:x="https://schemas.microsoft.com/office/2008/07/excelservices/rest" xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservice" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <title type="text">Charts</title>
  <id>https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts</id>
  <updated>2010-01-19T19:32:53Z</updated>
  <author>
    <name />
  </author>
  <link rel="self" href="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts?$format=atom" title="Charts" />
  <entry>
    <category term="ExcelServices.Chart" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <title>Chart 1</title>
    <id>https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%201')</id>
    <updated>2010-01-19T19:32:53Z</updated>
    <author>
      <name />
    </author>
    <link rel="alternate" title="Chart 1" href="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%201')?$format=image" />
    <content type="image/png" src="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%201')?$format=image" />
  </entry>
  <entry>
    <category term="ExcelServices.Chart" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <title>Chart 3</title>
    <id>https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%203')</id>
    <updated>2010-01-19T19:32:53Z</updated>
    <author>
      <name />
    </author>
    <link rel="alternate" title="Chart 3" href="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%203')?$format=image" />
    <content type="image/png" src="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('Chart%203')?$format=image" />
  </entry>
  <entry>
    <category term="ExcelServices.Chart" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <title>SampleChart </title>
    <id>https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('SampleChart%20')</id>
    <updated>2010-01-19T19:32:53Z</updated>
    <author>
      <name />
    </author>
    <link rel="alternate" title="SampleChart" href="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('SampleChart%20')?$format=image" />
    <content type="image/png" src="https://ServerName/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/model/Charts('SampleChart%20')?$format=image" />
  </entry>
</feed>

请参阅

概念

Excel Services REST API 的资源 URI