我正在尝试从sharepoint读取excel文件到python。
Q1:文件有两个URL。如果我直接复制文件的链接,我会得到:
https://company.sharepoint.com/:x:/s/project/letters-numbers?e=lettersnumbers
如果我一个接一个地从网页中单击“进入文件夹”,直到单击并打开excel文件,URL现在为:
https://company.sharepoint.com/:x:/r/sites/project/_layouts/15/Doc.aspx?sourcedoc=letters-numbers&file=Table.xlsx&action=default&mobileredirect=true
我应该用哪一种?
Q2:下面是我的代码:
import pandas as pd
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
URL = "https://company.sharepoint.com/:x:/s/project/letters-numbers?e=lettersnumbers"
USERNAME = "abc@a.com"
PASSWORD = "abcd"
ctx_auth = AuthenticationContext(URL)
if ctx_auth.acquire_token_for_user(USERNAME, PASSWORD):
ctx = ClientContext(URL, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
print("Authentication successful")
else:
print(ctx_auth.get_last_error())
response = File.open_binary(ctx, URL)
bytes_file_obj = io.BytesIO()
bytes_file_obj.write(response.content)
bytes_file_obj.seek(0)
df = pd.read_excel(bytes_file_obj, sheet_name="Sheet2")
它的工作直到pd.read_excel()
,在那里我得到了ValueError。
ValueError: Excel file format cannot be determined, you must specify an engine manually.
我不知道哪里出了问题,装船是否会有进一步的问题。如果有人能提醒我这些问题或者留下一个例子,那将是非常感激的。
发布于 2022-07-13 11:09:02
如果您查看“read_excel”(excel.html)的熊猫文档,您将看到有一个“engine”参数。
尝试不同的选项,看看哪个可以工作,因为您的错误是说引擎必须手动指定。
如果这是正确的,那么在将来,从字面上看错误信息并检查文档。
https://stackoverflow.com/questions/72965110
复制相似问题