-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worksheet enhancements & example to return grouped items from a list (#…
…806)
- Loading branch information
Showing
5 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Gets the range object containing the single cell based on row and column numbers. | ||
https://learn.microsoft.com/en-us/graph/api/worksheet-cell?view=graph-rest-1.0 | ||
""" | ||
import sys | ||
|
||
from office365.graph_client import GraphClient | ||
from tests import test_client_id, test_password, test_tenant, test_username | ||
|
||
client = GraphClient.with_username_and_password( | ||
test_tenant, test_client_id, test_username, test_password | ||
) | ||
drive_item = client.me.drive.root.get_by_path("Financial Sample.xlsx") | ||
worksheets = drive_item.workbook.worksheets.get().execute_query() | ||
if len(worksheets) == 0: | ||
sys.exit("No worksheets found") | ||
|
||
|
||
result = worksheets["Sheet1"].cell(row=1, column=1).execute_query() | ||
print(result.values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from office365.sharepoint.client_context import ClientContext | ||
from office365.sharepoint.listitems.caml.query import CamlQuery | ||
from tests import test_client_credentials, test_team_site_url | ||
|
||
|
||
def create_custom_query(): | ||
qry = CamlQuery() | ||
qry.FolderServerRelativeUrl = "Shared Documents/Archive" | ||
return qry | ||
|
||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials) | ||
lib = ctx.web.lists.get_by_title("Documents") | ||
result = lib.get_items(create_custom_query()).execute_query() | ||
for item in result: | ||
print(item.properties) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Demonstrates how to return distinct values from a List for the specific column, where: | ||
- render_list_data is used to returns the data for the specified query view | ||
""" | ||
|
||
import json | ||
|
||
from office365.sharepoint.client_context import ClientContext | ||
from tests import test_client_credentials, test_team_site_url | ||
|
||
view_xml = """ | ||
<View> | ||
<Query> | ||
<GroupBy Collapse="TRUE" GroupLimit="100"> | ||
<FieldRef Name="Author"/> | ||
</GroupBy> | ||
</Query> | ||
<ViewFields> | ||
<FieldRef Name="Author"/> | ||
</ViewFields> | ||
<RowLimit Paged="TRUE">100</RowLimit> | ||
</View> | ||
""" | ||
|
||
ctx = ClientContext(test_team_site_url).with_credentials(test_client_credentials) | ||
lib = ctx.web.lists.get_by_title("Site Pages") | ||
result = lib.render_list_data(view_xml).execute_query() | ||
data = json.loads(result.value) | ||
for item in data.get("Row"): | ||
print(item.get("Author.title")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters