在本地创建好表格,写入数据。在Python中引入xlrd包。
表格中的数据:
对表格中的数据进行组合,具体代码如下:
#coding: utf8
import xlrd
data = xlrd.open_workbook(r"D:\数据.xls")#打开表格
table = data.sheet_by_name('Sheet1')#读取Sheet页
a = 0
b = 0
c = 0
while a < 30:
print(table.cell_value(a, 0), table.cell_value(b, 1), table.cell_value(c, 2))#table.cell_value(a, 0)/(行/列)
c += 1
if c == 30:
c = 0
b += 1
if b == 30:
b = 0
a += 1
运行结果:
D:\Python\python39.exe "D:/PyCharm Community Edition 2021.2.2/xin/biao.py"
1.0 1.0 1.0
1.0 1.0 2.0
1.0 1.0 3.0
1.0 1.0 4.0
1.0 1.0 5.0
1.0 1.0 6.0
1.0 1.0 7.0
1.0 1.0 8.0
1.0 1.0 9.0
1.0 1.0 10.0
1.0 1.0 11.0
1.0 1.0 12.0
1.0 1.0 13.0
1.0 1.0 14.0
1.0 1.0 15.0
1.0 1.0 16.0
1.0 1.0 17.0
1.0 1.0 18.0
1.0 1.0 19.0
1.0 1.0 20.0
1.0 1.0 21.0
1.0 1.0 22.0
1.0 1.0 23.0
1.0 1.0 24.0
1.0 1.0 25.0
1.0 1.0 26.0
1.0 1.0 27.0
1.0 1.0 28.0
1.0 1.0 29.0
1.0 1.0 30.0
1.0 2.0 1.0
1.0 2.0 2.0
1.0 2.0 3.0
1.0 2.0 4.0
1.0 2.0 5.0
1.0 2.0 6.0
1.0 2.0 7.0
1.0 2.0 8.0
1.0 2.0 9.0
1.0 2.0 10.0
1.0 2.0 11.0
'''太多了,中间省略'''
30.0 29.0 17.0
30.0 29.0 18.0
30.0 29.0 19.0
30.0 29.0 20.0
30.0 29.0 21.0
30.0 29.0 22.0
30.0 29.0 23.0
30.0 29.0 24.0
30.0 29.0 25.0
30.0 29.0 26.0
30.0 29.0 27.0
30.0 29.0 28.0
30.0 29.0 29.0
30.0 29.0 30.0
30.0 30.0 1.0
30.0 30.0 2.0
30.0 30.0 3.0
30.0 30.0 4.0
30.0 30.0 5.0
30.0 30.0 6.0
30.0 30.0 7.0
30.0 30.0 8.0
30.0 30.0 9.0
30.0 30.0 10.0
30.0 30.0 11.0
30.0 30.0 12.0
30.0 30.0 13.0
30.0 30.0 14.0
30.0 30.0 15.0
30.0 30.0 16.0
30.0 30.0 17.0
30.0 30.0 18.0
30.0 30.0 19.0
30.0 30.0 20.0
30.0 30.0 21.0
30.0 30.0 22.0
30.0 30.0 23.0
30.0 30.0 24.0
30.0 30.0 25.0
30.0 30.0 26.0
30.0 30.0 27.0
30.0 30.0 28.0
30.0 30.0 29.0
30.0 30.0 30.0