我正在创建一个OData提供程序,用于与PHP库一起使用Excel:https://github.com/Algo-Web/POData
我已经设法在我的本地网络上的浏览器中提供了一个Sample数据集:
http://dss.example.com/proto/odata.svc/Samples?$ format = json
{
"value":[
{
"id":"1","firstName":"Rebbecca","lastName":"Didio","companyName":"Brandt, Jonathan F Esq","address":"171 E 24th St","city":"Leith","state":"TA","post":"7315","phone1":"03-8174-9123","phone2":"0458-665-290","email":"rebbecca.didio@didio.com.au","web":"http://www.brandtjonathanfesq.com.au"
},{
"id":"2","firstName":"Stevie","lastName":"Hallo","companyName":"Landrum Temporary Services","address":"22222 Acoma St","city":"Proston","state":"QL","post":"4613","phone1":"07-9997-3366","phone2":"0497-622-620","email":"stevie.hallo@hotmail.com","web":"http://www.landrumtemporaryservices.com.au"
},{
"id":"3","firstName":"Mariko","lastName":"Stayer","companyName":"Inabinet, Macre Esq","address":"534 Schoenborn St #51","city":"Hamel","state":"WA","post":"6215","phone1":"08-5558-9019","phone2":"0427-885-282","email":"mariko_stayer@hotmail.com","web":"http://www.inabinetmacreesq.com.au"
},{
"id":"4","firstName":"Gerardo","lastName":"Woodka","companyName":"Morris Downing & Sherred","address":"69206 Jackson Ave","city":"Talmalmo","state":"NS","post":"2640","phone1":"02-6044-4682","phone2":"0443-795-912","email":"gerardo_woodka@hotmail.com","web":"http://www.morrisdowningsherred.com.au"
},{
"id":"5","firstName":"Mayra","lastName":"Bena","companyName":"Buelt, David L Esq","address":"808 Glen Cove Ave","city":"Lane Cove","state":"NS","post":"1595","phone1":"02-1455-6085","phone2":"0453-666-885","email":"mayra.bena@gmail.com","web":"http://www.bueltdavidlesq.com.au"
},{
"id":"6","firstName":"Idella","lastName":"Scotland","companyName":"Artesian Ice & Cold Storage Co","address":"373 Lafayette St","city":"Cartmeticup","state":"WA","post":"6316","phone1":"08-7868-1355","phone2":"0451-966-921","email":"idella@hotmail.com","web":"http://www.artesianicecoldstorageco.com.au"
},
...
}
Run Code Online (Sandbox Code Playgroud)
以及http://dss.example.com/proto/odata.svc/ $ metadata 上的相应元数据
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns="http://schemas.microsoft.com/ado/2009/11/edm" xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" Version="3.0">
<edmx:DataServices m:MaxDataServiceVersion="3.0" m:DataServiceVersion="3.0">
<Schema Namespace="Proto">
<EntityType OpenType="false" Abstract="false" Name="Sample">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Int64" Nullable="false"/>
<Property Name="firstName" Type="Edm.String" Nullable="false"/>
<Property Name="lastName" Type="Edm.String" Nullable="false"/>
<Property Name="companyName" Type="Edm.String" Nullable="false"/>
<Property Name="address" Type="Edm.String" Nullable="false"/>
<Property Name="city" Type="Edm.String" Nullable="false"/>
<Property Name="state" Type="Edm.String" Nullable="false"/>
<Property Name="post" Type="Edm.String" Nullable="false"/>
<Property Name="phone1" Type="Edm.String" Nullable="false"/>
<Property Name="phone2" Type="Edm.String" Nullable="false"/>
<Property Name="email" Type="Edm.String" Nullable="false"/>
<Property Name="web" Type="Edm.String" Nullable="false"/>
</EntityType>
<EntityContainer Name="Proto" m:IsDefaultEntityContainer="true">
<EntitySet Name="Proto" EntityType="Proto.Sample" cg:GetterAccess="Public"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Run Code Online (Sandbox Code Playgroud)
通过记录标题我确认Excel提出以下请求:
请求1显示所有数据.该库以JSON响应
User-Agent: Microsoft.Data.Mashup (https://go.microsoft.com/fwlink/?LinkID=304225)
MaxDataServiceVersion: 3.0
OData-MaxVersion: 4.0
Accept: application/json;odata.metadata=minimal;q=1.0,application/json;odata=minimalmetadata;q=0.9,application/atomsvc+xml;q=0.8,application/atom+xml;q=0.8,application/xml;q=0.7,text/plain;q=0.7
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Run Code Online (Sandbox Code Playgroud)
仅为JSON请求2
User-Agent: Microsoft.Data.Mashup (https://go.microsoft.com/fwlink/?LinkID=304225)
OData-MaxVersion: 4.0
Accept: application/json;odata.metadata=minimal
Accept-Encoding: gzip, deflate
Host: ds1.example.com
Run Code Online (Sandbox Code Playgroud)
该库以JSON响应
请求3为atom/xml
通过反复试验,我决定在这里返回元数据
User-Agent: Microsoft.Data.Mashup (https://go.microsoft.com/fwlink/?LinkID=304225)
MaxDataServiceVersion: 3.0
Accept: application/json;odata=minimalmetadata;q=1.0,application/atomsvc+xml;q=0.8,application/atom+xml;q=0.8,application/xml;q=0.7,text/plain;q=0.7
Accept-Encoding: gzip, deflate
Host: ds1.example.com
---Request Start: /proto/odata.svc/Samples---
User-Agent: Microsoft.Data.Mashup (https://go.microsoft.com/fwlink/?LinkID=304225)
MaxDataServiceVersion: 3.0
Accept: application/atomsvc+xml;q=0.8,application/atom+xml;q=0.8,application/xml;q=0.7,text/plain;q=0.7
Accept-Encoding: gzip, deflate
Run Code Online (Sandbox Code Playgroud)
但是,这会将PowerQuery中的XML元数据显示为查询结果.
我还修改了我的OData后端以返回xml,就像通过浏览器请求时一样:http:/dss.example.com/proto/odata.svc/Samples
对于此变体,Excel显示错误:
"Odata:给定的URL既不指向OData服务,也不指向Feed:"
我是OData的新手,这里的目的是通过Web门户提供表数据,而无需在运行Excel的机器上安装任何东西,否则我会使用ODBC
| 归档时间: |
|
| 查看次数: |
249 次 |
| 最近记录: |