用python处理远程服务器文件夹中的所有excel文件

2024-04-25 07:36:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要用Python编写一个程序来处理远程服务器文件夹中的所有excel文件。要在我的计算机上处理excel文件,我使用

from xlrd import open_workbook
book = open_workbook( filename)

然后处理book 但是,我不知道如何在远程服务器上获取一个excel文件来处理。请帮我一下。如果可能的话,请告诉我如何在远程服务器的文件夹中获取所有的excel文件。谢谢。在


Tags: 文件fromimport程序服务器文件夹远程计算机
1条回答
网友
1楼 · 发布于 2024-04-25 07:36:02
import os

excelfiles = []

for cwd, folders, files in os.walk(starting_directory):  # For file in starting_directory
    for filename in files:
        path = os.path.join(cwd, filename)
        if os.path.splitext(path)[1].lower() == '.xls':  # If the file ends in '.xls'
            excelfiles.append(path)

for spreadsheet in excelfiles:
    process_spreadsheet(spreadsheet)

相关问题 更多 >