如何读取Azure File Storage中的XLSX文件(无法下载至本地)
读取Azure File Storage中Excel文件的入门方法
一、先准备必要凭证
- 从Azure门户的存储账户页面,获取以下信息:存储账户名称、文件共享名称、存储账户密钥(或SAS令牌)。SAS令牌需包含读取权限(r),有效期要覆盖你的操作时段。
二、Python直接读取(无需本地下载)
这是最易上手的方案,结合Azure SDK和Pandas处理Excel:
- 安装依赖包:
pip install azure-storage-file-share pandas openpyxl
注:
openpyxl用于读取.xlsx格式,.xls格式需替换为xlrd
- 核心代码示例:
from azure.storage.fileshare import ShareFileClient import pandas as pd from io import BytesIO # 替换为你的实际信息 account_name = "your-storage-account-name" share_name = "your-file-share-name" file_path = "folder/subfolder/target-file.xlsx" account_key = "your-storage-account-key" # 连接到目标文件 file_client = ShareFileClient( account_url=f"https://{account_name}.file.core.windows.net", share_name=share_name, file_path=file_path, credential=account_key ) # 将文件读取到内存流 file_stream = BytesIO() download_stream = file_client.download_file() download_stream.readinto(file_stream) file_stream.seek(0) # 重置流指针到起始位置 # 用Pandas解析Excel df = pd.read_excel(file_stream, engine="openpyxl") print(df.head())
三、其他可选入门方案
- Azure Functions:无服务器场景下,创建Python/C#类型的Function,通过SDK直接访问File Storage读取文件,处理后输出结果,全程无需本地存储。
- Power Automate:低代码场景,使用"Azure File Storage"连接器直接读取文件内容,后续可对接Excel在线处理动作。
关键注意点
- 确保你的访问身份(账户密钥/SAS令牌对应的身份)拥有File Data Reader及以上权限,避免访问被拒。
内容的提问来源于stack exchange,提问作者Moshe Raab
相关产品推荐
相关产品推荐

