Excel Table 没有数据或架构的列
Excel Table Columns without Data, or Schema
我正在尝试将 table 的行加载到类型化集合中。我熟悉依赖于将行数据放入字符串数组的 "BuildList" 示例。但是,如果用户在 table 中插入列或重新排列列位置,则这不是很可靠。所以我想得到一个列列表及其在 table 中的顺序位置。
最好的方法是什么? /Rows 调用不会返回列名,而 /Columns 很好,但它也会返回所有列的所有数据。有没有办法恢复 Columns 但没有数据或其他一些调用来描述 table 模式(尽管我不希望获得数据类型)。
更新
我正在使用此处的示例应用程序:https://github.com/microsoftgraph/aspnet-donations-rest-sample/blob/master/Microsoft-Graph-ASPNET-Excel-Donations/ExcelAPIHelper.cs。具体来说,BuildList 方法使用了硬编码的字符串数组引用(第 108-112 行)。这是非常脆弱的,如果用户重新排列 excel 文件中的列,或者插入一个额外的列,就会中断。
我想从 table 中获取没有数据的列列表。列表列方法(即 table('MyTable')/列)returns 每列的所有数据值)。参见参考文献:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/table_list_columns。 ) 我希望这更清楚。
我发现您可以使用 OData 查询参数,只需使用 $select=name,index 提取列的名称和索引。
https://graph.microsoft.com/beta/drives/omitted/items/omitted/workbook/worksheets('Sheet2')/tables('Table2')/Columns?$select=name,index
和结果 json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#drives('omitted')/items('omitted')/workbook/worksheets('Sheet2')/tables('Table2')/columns(name)",
"value": [
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%279%27)",
"id": "9",
"name": "Date"
},
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%2710%27)",
"id": "10",
"name": "Time"
},
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%2711%27)",
"id": "11",
"name": "Rink"
}
}
我正在尝试将 table 的行加载到类型化集合中。我熟悉依赖于将行数据放入字符串数组的 "BuildList" 示例。但是,如果用户在 table 中插入列或重新排列列位置,则这不是很可靠。所以我想得到一个列列表及其在 table 中的顺序位置。
最好的方法是什么? /Rows 调用不会返回列名,而 /Columns 很好,但它也会返回所有列的所有数据。有没有办法恢复 Columns 但没有数据或其他一些调用来描述 table 模式(尽管我不希望获得数据类型)。
更新 我正在使用此处的示例应用程序:https://github.com/microsoftgraph/aspnet-donations-rest-sample/blob/master/Microsoft-Graph-ASPNET-Excel-Donations/ExcelAPIHelper.cs。具体来说,BuildList 方法使用了硬编码的字符串数组引用(第 108-112 行)。这是非常脆弱的,如果用户重新排列 excel 文件中的列,或者插入一个额外的列,就会中断。
我想从 table 中获取没有数据的列列表。列表列方法(即 table('MyTable')/列)returns 每列的所有数据值)。参见参考文献:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/table_list_columns。 ) 我希望这更清楚。
我发现您可以使用 OData 查询参数,只需使用 $select=name,index 提取列的名称和索引。
https://graph.microsoft.com/beta/drives/omitted/items/omitted/workbook/worksheets('Sheet2')/tables('Table2')/Columns?$select=name,index
和结果 json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#drives('omitted')/items('omitted')/workbook/worksheets('Sheet2')/tables('Table2')/columns(name)",
"value": [
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%279%27)",
"id": "9",
"name": "Date"
},
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%2710%27)",
"id": "10",
"name": "Time"
},
{
"@odata.id": "/drives('omitted')/items('omitted')/workbook/worksheets(%27%7B00000000-0001-0000-0100-000000000000%7D%27)/tables(%272%27)/columns(%2711%27)",
"id": "11",
"name": "Rink"
}
}