读Excel,方法一:
1
2
3
4
5
6
7
8
9
10
|
import xlrd
from tqdm import tqdm
workbook = xlrd.open_workbook('some.xlsx')
sheet = workbook.sheet_by_name('sheet1')
#sheet = workbook.sheet_by_index(0)
nrows = sheet.nrows
for idx in tqdm(range(1, nrows)):
data = sheet.cell_value(idx, 0)
|
写Excel,方法一(支持xls,小于6w行数):
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import xlwt
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('sheet1')
sheet.write(0, 0, 'Head_1')
idx = 1
for row in tqdm(datas):
sheet.write(idx, 0, row['data_1'])
idx += 1
workbook.save('some.xls')
|
写Excel,方法二(支持xlsx,大于6w行数):
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import xlsxwriter
workbook = xlsxwriter.Workbook('some.xls')
sheet = workbook.add_worksheet('sheet1')
sheet.write(0, 0, 'Head_1')
idx = 1
for row in tqdm(datas):
sheet.write(idx, 0, row['data_1'])
idx += 1
workbook.close()
|