我正在尝试将Excel文件从SharePoint读取到python,并收到以下错误:
- 值错误:无法确定Excel文件格式,必须手动指定引擎 *
我的代码:
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
url_sp = 'https://company.sharepoint.com/teams/TeamE'
username_sp = 'MyUsername'
password_sp = 'MyPassword'
folder_url_sp = '/Shared%20Documents/02%20Team%20IAP/06_Da-An/Data/E/Edate.xlsx?web=1'
#Authentication
ctx_auth = AuthenticationContext(url_sp)
if ctx_auth.acquire_token_for_user(username_sp, password_sp):
ctx = ClientContext(url_sp, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print('Authentication sucessfull')
else:
print(ctx_auth.get_last_error())
import io
response = File.open_binary(ctx,folder_url_sp)
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)
data = pd.read_excel(bytes_file_obj,sheet_name = None)
这是否与Excel文件由多个工作表组成有关?您能进一步帮助我吗?
先谢了
1条答案
按热度按时间nfeuvbwi1#
几个工作表应该不是问题。你试过像错误消息说的那样在代码中指定引擎吗?
第一个月
可能的选项可以在Pandashere的文档中找到(向下滚动到
engine: str, default None
)。如果io不是缓冲区或路径,则必须将其设置为标识io
似乎适合你适合你的问题