iT邦幫忙

0

透過拖曳方式,用python讀取特定excel

我現在做了一個讀去excel檔案的python並包成read.exe去執行。

目前已完成的部分是我可以讀取跟read.exe相同路徑內的excel檔案並去做選擇看要使用哪一個excel檔。

現在想要讓他變成,我直接拖曳我要選擇的excel檔案到read.exe上面,read.exe會直接知道我需要的是哪一個excel並用他去執行。

以下是我目前讀取同路徑excel檔以及選擇的方法

#get excel name
filelist=[]
for root, dirs, files in os.walk(".", topdown=False):
    for name in files:
        str=os.path.join(root, name)
        if str.split('.')[-1]=='xlsx':
            filelist.append(str)
print("Excel in your Folder:")
print(filelist)
check = input("Choose Excel(1、2、3...) : ")
filename = filelist[int(check)-1][2:]
print("Excel Name : ",filename)

#xlsx
workbook = xlrd.open_workbook(filename,'r')
sheet = workbook.sheet_by_index(0)
c_cols = sheet.col_values(0)
c_row = sheet.row_values(0)
data_set = list()

想問各位有沒有什麼方法可以實現我想要拖曳excel檔案到read.exe檔然後直接利用該excel檔案的檔名去做執行

感謝!!

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2019-10-09 09:56:55
最佳解答

關鍵字:sys.argv

如果看這篇好像連編譯成 exe 都省了
/images/emoticon/emoticon07.gif

選我正解

原來如此 太感謝了

我要發表回答

立即登入回答