質問編集履歴
2
補足項目を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -195,3 +195,5 @@
|
|
195
195
|
|
196
196
|
|
197
197
|
```
|
198
|
+
|
199
|
+
補足:sheet.cell(row=r, column=10).valueの値は空白セルか整数値が入っています。
|
1
試行錯誤1項目以下が追記となります。
test
CHANGED
File without changes
|
test
CHANGED
@@ -103,3 +103,95 @@
|
|
103
103
|
TypeError: type NoneType doesn't define __round__ method
|
104
104
|
|
105
105
|
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
試行錯誤1:エラーを受けて、sheet.cell(row=r, column=10).valueに空白セルがいくつかあるので、
|
110
|
+
|
111
|
+
Noneというエラーが出たと解釈した上でのコード変更を下記のようにifで制御してみましたが
|
112
|
+
|
113
|
+
結果は同じ内容のエラーでした。
|
114
|
+
|
115
|
+
解決策をご教授いただきますようお願い致します。
|
116
|
+
|
117
|
+
```ここに言語を入力
|
118
|
+
|
119
|
+
import openpyxl
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
report_path = 'rpa db_tok_report.xlsx'
|
126
|
+
|
127
|
+
assign_path = 'rpa 41得意先管理(大阪).xlsx'
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
wb = openpyxl.load_workbook(report_path, data_only=True, read_only=True)
|
132
|
+
|
133
|
+
sheet = wb.active
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
#売上実績を読み込む
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
report = {}
|
142
|
+
|
143
|
+
for r in range(2, sheet.max_row+1):
|
144
|
+
|
145
|
+
name = sheet.cell(row=r, column=2).value
|
146
|
+
|
147
|
+
if sheet.cell(row=r, column=10).value=='':
|
148
|
+
|
149
|
+
uriage=''
|
150
|
+
|
151
|
+
else:
|
152
|
+
|
153
|
+
uriage=round(sheet.cell(row=r, column=10).value,-3)//1000
|
154
|
+
|
155
|
+
report[name]={'uriage':uriage}
|
156
|
+
|
157
|
+
print(report)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
#出力用のファイルを読み込む
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
out_wb = openpyxl.load_workbook(assign_path)
|
168
|
+
|
169
|
+
out_sheet = out_wb.get_sheet_by_name('データ')
|
170
|
+
|
171
|
+
for r in range(2, out_sheet.max_row+1):
|
172
|
+
|
173
|
+
name = out_sheet.cell(row=r, column=2).value
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
#名前に応じた売上を書き込む
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
if name in report:
|
182
|
+
|
183
|
+
out_sheet.cell(row=r, column=11).value = report[name]['uriage']
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
#書き込み後の保存
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
out_wb.save(assign_path)
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
```
|