2
嗨使用openpyxl模塊格式化電子表格。我試圖加入列A和B的每行「,」並刪除列B的數字中的「 - 」。 我也試圖刪除列中有「無」的任何行。我有第一部分,但我無法刪除「無」和整個行。下面你會看到我的代碼,然後是我期望實現的前後。我將非常感謝您的幫助,因爲我仍然是Python的noobie。Python Openpyxl ...刪除具有特定單詞的行
**Code**
import openpyxl
wb = openpyxl.load_workbook('Users.xlsx')
sheet = wb.get_active_sheet()
for rows in sheet['A3':'B11']:
try:
print(rows[0].value + "," + rows[1].value.replace("-",""))
# TODO: remove rows with the word "None"
except:
if rows == "None":
rows[0].value.delete
continue
**Before**
b0119xxx None
b0105xxx 534-0498
c0215xxx 534-0498
c0245xxx None
d0232xxx 534-0498
d0263xxx 534-0498
d0190xxx 534-0498
d0085xxx None
g0009xxx 534-0498
g0169xxx 534-0498
g0221xxx 534-0498
**After**
b0105xxx,5340498
c0215xxx,5340498
d0232xxx,5340498
d0263xxx,5340498
d0190xxx,5340498
g0009xxx,5340498
g0169xxx,5340498
g0221xxx,5340498