该部分代码主要学习了:
1.Python代码中删除指定的数组
2.xlrd中,row_values的用法
1 import xlrd
2 from xlutils.copy import copy
3 # import numpy as np
4
5 data = xlrd.open_workbook('Antenna.xlsx')
6 data2 = xlrd.open_workbook('Antenna12Bit.xlsx')
7 wdata = copy(data2)
8 woutput = wdata.get_sheet('CROSSMIPI')
9
10 stateinput = data.sheet_by_name('STATEINPUT')
11 commandinput = data.sheet_by_name('COMMANDINPUT')
12
13 state_rows = stateinput.nrows
14 state_cols = stateinput.ncols
15
16 command_rows = commandinput.nrows
17 command_cols = commandinput.ncols
18
19 # initial
20 i = 0
21 j = 0
22 k = 0
23 m = 0
24 n = 0
25
26 u1 = 0
27 u2 = 0
28 u3 = 0
29 u4 = 0
30 u5 = 0
31
32 tunerstate = 3
33
34 gpio = 0
35
36 band_config = []
37
38 for i in range(state_rows - 1):
39 band_config.append([])
40 band_config[m] = stateinput.cell_value(i + 1, 7)
41 m = m + 1
42
43 band_config = list(set(band_config))
44 m = 0
45
46
47 for i in range(state_rows - 1):
48 if stateinput.cell_value(i + 1, 7) in band_config:
49
50 u1 = stateinput.cell_value(i + 1, 2)
51 u2 = stateinput.cell_value(i + 1, 3)
52 u3 = stateinput.cell_value(i + 1, 4)
53 u4 = stateinput.cell_value(i + 1, 5)
54 u5 = stateinput.cell_value(i + 1, 6)
55
56 u1mipi = commandinput.row_values(int(u1) + 2, 2, 6)
57 u2mipi = commandinput.row_values(int(u2) + tunerstate + 2, 2, 6)
58 u3mipi = commandinput.row_values(int(u3) + tunerstate * 2 + 2, 2, 6)
59 u4mipi = commandinput.row_values(int(u4) + tunerstate * 3 + 2, 2, 6)
60 u5mipi = commandinput.row_values(int(u5) + tunerstate * 4 + 2, 2, 6)
61
62 gpio = commandinput.cell_value(int(u1) + 2, 6) + commandinput.cell_value(int(u2) + tunerstate + 2, 6) + commandinput.cell_value(int(u3) + tunerstate * 2 + 2, 6) + commandinput.cell_value(int(u4) + tunerstate * 3 + 2, 6) + commandinput.cell_value(int(u5) + tunerstate * 4 + 2, 6)
63
64 for j in range(4):
65 woutput.write(k * 2 + 3, j + 2, u1mipi[j])
66 woutput.write(k * 2 + 3, j + 2 + 5, u2mipi[j])
67 woutput.write(k * 2 + 3, j + 2 + 5 * 2, u3mipi[j])
68 woutput.write(k * 2 + 3, j + 2 + 5 * 3, u4mipi[j])
69 woutput.write(k * 2 + 3, j + 2 + 5 * 4, u5mipi[j])
70
71 for j in range(12):
72 m = int(gpio / 2**(19 - j))
73 gpio = gpio - m * 2**(19 - j)
74 if m >= 0:
75 woutput.write(k * 2 + 3, 27 + j, m)
76 else:
77 woutput.write(k * 2 + 3, 27 + j, 0)
78
79 woutput.write(k * 2 + 3, 1, stateinput.cell_value(i + 1, 7))
80
81 k = k + 1
82 band_config.remove(stateinput.cell_value(i + 1, 7))
83
84 wdata.save('Antenna12Bit.xlsx')