How to read text from an Excel table range using MS Graph? - excel

I have previously been reading the text from a table in excel using the following URL:
https://graph.microsoft.com/v1.0/me/drive/root:/my-folder%5Cmy-workbook.xlsx:/workbook/worksheets('MyWorksheet')/tables('MyTable')/range/text
Now that is giving me a 200 response with this content:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.Json"
}
I can access the range using the same URL but without the \text segment. For example the requests to the following URL
https://graph.microsoft.com/v1.0/me/drive/root:/my-folder%5Cmy-workbook.xlsx:/workbook/worksheets('MyWorksheet')/tables('MyTable')/range
result in:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#workbookRange",
"#odata.type": "#microsoft.graph.workbookRange",
"#odata.id": "/users('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')/drive/root/workbook/worksheets(%27%7Bxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%7D%27)/tables(%2719%27)/range()",
"address": "MyWorksheet!C6:BB18",
"addressLocal": "MyWorksheet!C6:BB18",
"cellCount": 676,
"columnCount": 52,
"columnHidden": false,
"columnIndex": 2,
"formulas": [ ... ],
"formulasLocal": [ ... ],
"formulasR1C1": [ ... ],
"hidden": false,
"numberFormat": [ ... ],
"rowCount": 13,
"rowHidden": false,
"rowIndex": 5,
"text": [
[
"Text",
"From",
"The",
"Range",
...,
]
]
"values": [ ... ],
"valueTypes": [ ....]
}
The text property is present and contains the expected data.
The MS Graph documentation includes a text property on the range resource.
As stated above, I believe this was working earlier, so I'm assuming this is due to some bug / change / limitaion in MS Graph.
Can anyone advise how to read the text from that table range directly (and/or why I am getting that response)?

Text is a property of the microsoft.graph.workbookRang, but not an endpoint. I'm not sure how/if /range/text could have worked in the past but I wouldn't have expected it to.
As for returning just the text, you can use the $select query parameter:
/me/drive/root:/{path}:/workbook/worksheets('{id}')/tables('{id}')/range?$select=text

Related

Convert data from spreadsheets to nested json

I'm using mongodb in my project. And I'll import about 20,000 products to the database in the end. So, I tried to write a script to convert the data from the spreadsheet to json, and then upload them to the mongodb. But many fields were missing.
I'm trying to figure out how to layout the spreadsheet so it would contain nested data. But I didn't find any resources to do so but only this package:
https://www.npmjs.com/package/spread-sheet-to-nested-json
But it has one problem, it will always contain "title" and "children", not the actual name of the field.
This is my product json:
[
{
"sku": "ADX112",
"name": {
"en": "Multi-Mat Gallery Frames",
"ar": "لوحة بإطار"
},
"brand": "Dummy brand",
"description": {
"en": "Metal frame in a Black powder-coated finish. Tempered glass. 2 removable, acid-free paper mats included with each frame. Can be hung vertically and horizontally. D-rings included. 5x7 and 8x10 frames include easel backs. Sold individually. Made in China.",
"ar": "إطار اسود. صنع في الصين."
},
"tags": [
"art",
"frame",
"لوحة",
"إطار"
],
"colors": [
"#000000"
],
"dimensions": [
"5x7",
"8x10"
],
"units_in_stock": {
"5x7": 5,
"8x10": 7
},
"thumbnail": "https://via.placeholder.com/150",
"images": [
"https://via.placeholder.com/150",
"https://via.placeholder.com/150"
],
"unit_size": {
"en": [
"individual",
"set of 3"
],
"ar": [
"فردي",
"مجموعة من 3"
]
},
"unit_price": 2000,
"discount": 19,
"category_id": "631f3ca65b2310473b978ab5",
"subCategories_ids": [
"631f3ca65b2310473b978ab5",
"631f3ca65b2310473b978ab5"
],
"featured": false
}
]
How can I layout a spreadsheet so it would be a template for future imports?

Azure Form Recognizer Not Behaving As Expected

I am having an issue with FormRecognizer not behaving how I have seen it should. Here is the dilemma
I have an Invoice that, when run through https://{endpoint}/formrecognizer/v2.0/layout/analyze
it recognized the table in the Invoice and generates the proper JSON with the "tables" node. Here is an example of part of it
{
"rows": 8,
"columns": 8,
"cells": [
{
"rowIndex": 0,
"columnIndex": 4,
"columnSpan": 3,
"text": "% 123 F STREET Deer Park TX 71536",
"boundingBox": [
3.11,
2.0733
],
"elements": [
"#/readResults/0/lines/20/words/0",
"#/readResults/0/lines/20/words/1"
]
}
When I train a model with NO labels file https://{endpoint}/formrecognizer/v2.0/custom/models It does not generate an empty "tables" node, but it generates (tokens). Here is an example of the one above without "table"
{
"key": {
"text": "__Tokens__12",
"boundingBox": null,
"elements": null
},
"value": {
"text": "123 F STREET",
"boundingBox": [
5.3778,
2.0625,
6.8056,
2.0625,
6.8056,
2.2014,
5.3778,
2.2014
],
"elements": null
},
"confidence": 1.0
}
I am not sure exactly where this is not behaving how intended, but any insight would be appreciated!
If you train a model WITH labeling files, then call FR Analyze(), the FR service will call the Layout service, which returns tables in "pageResults" section.

Invalid blockchain Json data

I have a huge text file with blockchain data that I'd like to parse so that I can get the info from the fields I need. I have tried to convert it to json but it says is invalid. After doing some thought, I've realised it is not the best way since I only want 2 or 3 fields. Can someone help me to find the best way of extracting data from the file? There's an example below. I would only want txid size, and hash.
{
"txid": "254d5cc8d2b1889a2cb45f7e3dca8ed53a3fcfa32e8b9eac5f68c4f09e7af7bd",
"hash": "a8e125eb6d7ab883177d8ab228a3d09c1733d1ca49b7b2dff4b057eeb80ff9be",
"version": 2,
"size": 171,
"vsize": 144,
"weight": 576,
"locktime": 0,
"vin": [
{
"coinbase": "02ee170101",
"sequence": 4294967295
}
],
"vout": [
{
"value": 12.00000000,
"n": 0,
"scriptPubKey": {
"asm": "OP_HASH160 cd5b833dd43bc60b8c28c4065af670f283a203ff OP_EQUAL",
"hex": "a914cd5b833dd43bc60b8c28c4065af670f283a203ff87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2NBy4928yJakYBFQuXxXBwXjsLCRWgzyiGm"
]
}
},
{
"value": 5.00000000,
"n": 1,
"scriptPubKey": {
"asm": "OP_HASH160 cd5b833dd43bc60b8c28c4065af670f283a203ff OP_EQUAL",
"hex": "a914cd5b833dd43bc60b8c28c4065af670f283a203ff87",
"reqSigs": 1,
"type": "scripthash",
"addresses": [
"2NBy4928yJakYBFQuXxXBwXjsLCRWgzyiGm"
]
}
}
],
"hex":
"020000000001010000000000000000000000000000000000000000000000000000000000000000
ffffffff0502ee170101ffffffff02000000000000000017a914cd5b833dd43bc60b8c28c4065af670f283a
203ff870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c69068979996
2b48bebd836974e8cf9012000000000000000000000000000000000000000000000000000000000
0000000000000000",
"blockhash": "0f84abb78891a4b9e8bc9637ec5fb8b4962c7fe46092fae99e9d69373bf7812a",
"confirmations": 1,
"time": 1590830080,
"blocktime": 1590830080
}
Thank you
#andrewjames is correct. If you have no control over the JSON file, you can address the error by just removing the newline characters:
parsed = json.loads(jsonText.replace("\n", ""))
Then you can access the fields you want like a normal dictionary:
print(parsed['txid'])

List out the table content from a Shared Excel file by using API

I have an excel table and which is shared by my colleague. I want to retrieve the table data by using the Excel API.
What I did first, I have uploaded a sample excel file with a table content in my OneDrive Account (Business);
and executed the below API by using Microsoft Graph Explorer and got the result as expected.
API - 1: https://graph.microsoft.com/v1.0/me/drive/root:/Employee_Details.xlsx:/workbook/tables/table1/columns
Response(expected)
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4f26b2bb-0260-43f6-bf09-6d7bc68fc09b')/drive/root/workbook/tables('table1')/columns",
"value": [
{
"#odata.id": "/users('4f26b2bb-0260-43f6-bf09-6d7bc68fc09b')/drive/root/workbook/tables(C4FE79CADFC5%7D%27)/columns(%271%27)",
"values": [
["Name"],
["MS Virat"]
],
"id": "1",
"index": 0,
"name": "Name"
},
{
"#odata.id": "/users('4f26b2bb-0260-43f6-bf09-6d7bc68fc09b')/drive/root/workbook/tables(C4FE79CADFC5%7D%27)/columns(%272%27)",
"values": [
["Status"],
["Batting"]
],
"id": "2",
"index": 1,
"name": "Status"
}
]
}
This below API can help to list out all the items Shared to me,
API - 2
https://graph.microsoft.com/v1.0/me/drive/sharedWithMe
My question is, what modification I need to do in the below API URL to list out the column details of a Shared Excel Table.
https://graph.microsoft.com/v1.0/me/drive/sharedWithMe
Thank You,

Marklogic 8 Node.js API - How can I scope a search on a property child of root?

[updated 17:15 on 28/09]
I'm manipulating json data of type:
[
{
"id": 1,
"title": "Sun",
"seeAlso": [
{
"id": 2,
"title": "Rain"
},
{
"id": 3,
"title": "Cloud"
}
]
},
{
"id": 2,
"title": "Rain",
"seeAlso": [
{
"id": 3,
"title": "Cloud"
}
]
},
{
"id": 3,
"title": "Cloud",
"seeAlso": [
{
"id": 1,
"title": "Sun"
}
]
},
];
After inclusion in the database, a node.js search using
db.documents.query(
q.where(
q.collection('test films'),
q.value('title','Sun')
).withOptions({categories: 'none'})
)
.result( function(results) {
console.log(JSON.stringify(results, null,2));
});
will return both the film titled 'Sun' and the films which have a seeAlso/title property (forgive the xpath syntax) = 'Sun'.
I need to find 1/ films with title = 'Sun' 2/ films with seeAlso/title = 'Sun'.
I tried a container query using q.scope() with no success; I don't find how to scope the root object node (first case) and for the second case,
q.where(q.scope(q.property('seeAlso'), q.value('title','Sun')))
returns as first result an item which matches all text inside the root object node
{
"index": 1,
"uri": "/1.json",
"path": "fn:doc(\"/1.json\")",
"score": 137216,
"confidence": 0.6202662,
"fitness": 0.6701325,
"href": "/v1/documents?uri=%2F1.json&database=Documents",
"mimetype": "application/json",
"format": "json",
"matches": [
{
"path": "fn:doc(\"/1.json\")/object-node()",
"match-text": [
"Sun Rain Cloud"
]
}
]
},
which seems crazy.
Any idea about how doing such searches on denormalized json data?
Laurent:
XPaths on JSON are supported by MarkLogic.
In particular, you might consider setting up a path range index to match /title at the root:
http://docs.marklogic.com/guide/admin/range_index#id_54948
Scoped property matching required either filtering or indexed positions to be accurate. An alternative is to set up another path range index on /seeAlso/title
For the match issue it would be useful to know the MarkLogic version and to see the entire query.
Hoping that helps,

Resources