回答編集履歴

2

一部修正

2020/09/27 11:10

投稿

nto
nto

スコア1438

test CHANGED
@@ -154,7 +154,7 @@
154
154
 
155
155
 
156
156
 
157
- target = 103754
157
+ target = 1000001
158
158
 
159
159
  color_dict = {'00000000': 'white', 'FFFF0000': 'red', 'FFFFFF00': 'yellow'}
160
160
 

1

追記

2020/09/27 11:10

投稿

nto
nto

スコア1438

test CHANGED
@@ -13,3 +13,197 @@
13
13
  >>> 00000000
14
14
 
15
15
  ```
16
+
17
+ ### 修正後
18
+
19
+ 諸々を修正し以下の様な形となり、自身としては問題の解決に至りました。
20
+
21
+ ```python
22
+
23
+ #-------Excel Window-------
24
+
25
+ def ExcelProcess(self):
26
+
27
+ # NewWindow create.
28
+
29
+ self.submaster = tk.Toplevel()
30
+
31
+ self.submaster.geometry('700x400')
32
+
33
+ self.submaster.grab_set()
34
+
35
+ self.submaster.attributes('-topmost', True)
36
+
37
+
38
+
39
+ ttk.Button(self.submaster, text='データ表示', command=self.ExcelDataGet).pack(pady=10)
40
+
41
+ self.BTN = ttk.Button(self.submaster, text='リセット', state='disable', command=self.TreeviewReset)
42
+
43
+ self.BTN.pack()
44
+
45
+
46
+
47
+ # Treeview create. set data of index and anchor together for tree.
48
+
49
+ tvframe = ttk.Frame(self.submaster)
50
+
51
+ tvframe.pack()
52
+
53
+ self.tree = ttk.Treeview(tvframe)
54
+
55
+ self.tree['column'] = tuple([i for i in range(7)])
56
+
57
+ tree_info = {'INDEX1': [70, tk.CENTER], 'INDEX2': [50, tk.CENTER], 'INDEX3': [70, tk.CENTER],
58
+
59
+ 'INDEX4': [60, tk.E], 'INDEX5': [150, tk.W], 'INDEX6': [50, tk.W], 'INDEX7': [120, tk.W]}
60
+
61
+ for i, [header, [width, anchor]] in enumerate(tree_info.items()):
62
+
63
+ self.tree.column(i, width=width, anchor=anchor)
64
+
65
+ self.tree.heading(i, text=header)
66
+
67
+ self.tree["show"] = "headings"
68
+
69
+ self.tree.grid(row=0, column=0)
70
+
71
+
72
+
73
+ # Scrollbar create.
74
+
75
+ ysb = tk.Scrollbar(tvframe, orient=tk.VERTICAL, width=16, command=self.tree.yview)
76
+
77
+ self.tree.configure(yscrollcommand=ysb.set)
78
+
79
+ ysb.grid(row=0, column=1, sticky='nsew')
80
+
81
+
82
+
83
+ def ColorChange(self, event):
84
+
85
+ tree = event.widget
86
+
87
+ for itemid in tree.selection():
88
+
89
+ tags = tree.item(itemid)['tags']
90
+
91
+ num = tags[0] # num for tag.
92
+
93
+ # For each color as specify the i, set bg in color & Rewring tags.
94
+
95
+ if 'white' in tags:
96
+
97
+ self.tree.tag_configure(num, background='red')
98
+
99
+ self.tree.item(itemid, tags=[num, 'red'])
100
+
101
+ break
102
+
103
+ elif 'red' in tags:
104
+
105
+ self.tree.tag_configure(num, background='yellow')
106
+
107
+ self.tree.item(itemid, tags=[num, 'yellow'])
108
+
109
+ break
110
+
111
+ elif 'yellow' in tags:
112
+
113
+ self.tree.tag_configure(num, background='white')
114
+
115
+ self.tree.item(itemid, tags=[num, 'white'])
116
+
117
+ break
118
+
119
+
120
+
121
+ self.tree.selection_set() # focus out, this is optimal...for me.
122
+
123
+
124
+
125
+ if str(self.BTN['state']) == 'disable': # a little strange. str??? whatever, its fine:(
126
+
127
+ self.BTN['state'] = 'normal'
128
+
129
+
130
+
131
+ def TreeviewReset(self):
132
+
133
+ if self.tree: # treeitems delete.
134
+
135
+ self.tree.delete(*self.tree.get_children())
136
+
137
+ for i, [value, color] in enumerate(self.data): # Rebuild.
138
+
139
+ self.tree.insert('','end', values=value, tags=[i, color])
140
+
141
+ self.tree.tag_configure(i, background=color)
142
+
143
+ self.BTN['state'] = 'disable' # Resetbutton has state change.
144
+
145
+
146
+
147
+ def ExcelDataGet(self):
148
+
149
+ # Ecelfile open.
150
+
151
+ wb = px.load_workbook(self.excel_path)
152
+
153
+ sheet = wb['Sheet1']
154
+
155
+
156
+
157
+ target = 103754
158
+
159
+ color_dict = {'00000000': 'white', 'FFFF0000': 'red', 'FFFFFF00': 'yellow'}
160
+
161
+ self.data = []
162
+
163
+ # Data create. Read line, Datetime attribute are convert and replace if blank.
164
+
165
+ for row in sheet.iter_rows():
166
+
167
+ if row[1].value == target:
168
+
169
+ tmp = []
170
+
171
+ for cell in row:
172
+
173
+ celldata = cell.value
174
+
175
+ if type(celldata) == datetime:
176
+
177
+ celldata = cell.value.strftime('%Y/%m/%d')
178
+
179
+ cellcolor = color_dict[cell.fill.fgColor.rgb] # 8 digit Colorcord get for here
180
+
181
+ elif celldata == None:
182
+
183
+ celldata = ''
184
+
185
+
186
+
187
+ tmp.append(celldata)
188
+
189
+ self.data.append([tmp, cellcolor])
190
+
191
+
192
+
193
+ # If data has target tree delete it.
194
+
195
+ if self.tree:
196
+
197
+ self.tree.delete(*self.tree.get_children())
198
+
199
+ # Set data for tree
200
+
201
+ for i, [value, color] in enumerate(self.data):
202
+
203
+ self.tree.insert('','end', values=value, tags=[i, color]) # [num, colorcorde] addition to tags.
204
+
205
+ self.tree.tag_configure(i, background=color) # Specify the i, set bg in color.
206
+
207
+ self.BTN['state'] = 'disable' # Resetbutton has state change.
208
+
209
+ ```