-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetdata.py
38 lines (30 loc) · 986 Bytes
/
getdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
import openpyxl
import os
import time
"""
@Auther : ga0weI
@Function : get specific column data form xlsx to txt
"""
def findcolnumbyname(name,ws):
for clnum in range(1, ws.max_column + 1):
if name in ws.cell(row=1, column=clnum).value:
return clnum
if __name__ == '__main__':
"""
两个参数,filename + cloumnname
"""
filename = sys.argv[1]
filepath = os.path.join(os.path.abspath("."), filename)
filecloum = sys.argv[2]
workbook = openpyxl.load_workbook(filepath)
ws = workbook.worksheets[0]
data_count = findcolnumbyname(filecloum, ws)
maxcolum = ws.max_column + 1
with open('data.txt','w') as f:
for i in range(2, ws.max_row + 1):
datas = ws.cell(row=i, column=data_count).value
if datas is not None:
datas =datas.replace('\n','')
f.write(datas+"\n")
print("从excel里面提取datas成功,并记录在data.txt文件中")