SharePointにあるエクセルファイルをO365ライブラリを用いてデータフレームに変換したいのです。
認証は問題なく行えています。
responseにはhtmlコードが返ってきます。
その中から必要なExcelのデータを抜き出す必要があるはずなのですが、どこを抜き出せばよいのかわかりません。
何かヒントがありましたら、教えて下さい。
<!DOCTYPE html> <html lang="ja-jp" dir="ltr" class="ms-isBot"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" /> <meta name="robots" content="noindex" /> <script type="text/javascript"> var wopiDiagClient = { docFirstFlushTime : new Date().getTime() } ; var _wopiContextJson ={"HostName":"SharePoint ・・・・・・
python
1from office365.runtime.auth.authentication_context import AuthenticationContext 2from office365.sharepoint.client_context import ClientContext 3from office365.sharepoint.files.file import File 4import io 5import pandas as pd 6import json 7 8url="https://*****.sharepoint.com/:x:/r/sites/PEB/Shared%20Documents/********.xlsx?d=w7a40fdfaa2404********cf00059&csf=1&web=1&e=****" 9username = '*********@************' 10password = '*******' 11 12ctx_auth = AuthenticationContext(url) 13if ctx_auth.acquire_token_for_user(username, password): 14 ctx = ClientContext(url, ctx_auth) 15 web = ctx.web 16 ctx.load(web) 17 ctx.execute_query() 18 print("Authentication successful") 19 20response = File.open_binary(ctx, url) 21 22bytes_file_obj = io.BytesIO() 23bytes_file_obj.write(response.content) 24bytes_file_obj.seek(0) 25 26print(bytes_file_obj.read()) 27 28df = pd.read_excel(bytes_file_obj, sheet_name = None) 29display(df) 30
Authentication successful --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-58-46c79dfd553a> in <module> 26 print(bytes_file_obj.read()) 27 ---> 28 df = pd.read_excel(bytes_file_obj, sheet_name = None) 29 display(df) D:\Anaconda3\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs) 297 ) 298 warnings.warn(msg, FutureWarning, stacklevel=stacklevel) --> 299 return func(*args, **kwargs) 300 301 return wrapper D:\Anaconda3\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, thousands, comment, skipfooter, convert_float, mangle_dupe_cols, storage_options) 334 if not isinstance(io, ExcelFile): 335 should_close = True --> 336 io = ExcelFile(io, storage_options=storage_options, engine=engine) 337 elif engine and engine != io.engine: 338 raise ValueError( D:\Anaconda3\lib\site-packages\pandas\io\excel\_base.py in __init__(self, path_or_buffer, engine, storage_options) 1069 ext = "xls" 1070 else: -> 1071 ext = inspect_excel_format( 1072 content=path_or_buffer, storage_options=storage_options 1073 ) D:\Anaconda3\lib\site-packages\pandas\io\excel\_base.py in inspect_excel_format(path, content, storage_options) 963 return "xls" 964 elif not peek.startswith(ZIP_SIGNATURE): --> 965 raise ValueError("File is not a recognized excel file") 966 967 # ZipFile typing is overly-strict ValueError: File is not a recognized excel file

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。