-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput_wordlist.py
More file actions
84 lines (77 loc) · 3.08 KB
/
Copy pathoutput_wordlist.py
File metadata and controls
84 lines (77 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def print_wordlist(wordlist):
for i in wordlist:
print(i['word']+'\t'+next((x for x in ref if x['PoS'] == i['pos']), None)['mean']+'\t'+i['lemma']+'\t'+i['phone']+'\t' + i['mean']+'\t' + i['identifier']+' p.' + str(i['page']))
def export_xlsx(wordlist):
export_file_path = 'newWordList.xlsm'
import openpyxl
wb = openpyxl.load_workbook('wordlist_templet.xlsm', keep_vba=True)
ws = wb['全リスト']
for i in range(0, len(wordlist)):
ws['B' + str(i + 2)].value = wordlist[i]['word']
ws['C' + str(i + 2)].value = wordlist[i]['pos_m']
ws['D' + str(i + 2)].value = wordlist[i]['phone']
ws['E' + str(i + 2)].value = wordlist[i]['mean']
try:
ws['F' + str(i + 2)].value = wordlist[i]['identifier']
ws['G' + str(i + 2)].value = wordlist[i]['page']
except KeyError:
ws['F' + str(i + 2)].value = ''
ws['G' + str(i + 2)].value = ''
try: # original_wordがないものもある。
ws['I' + str(i + 2)].value = wordlist[i]['original_word']
except KeyError:
ws['I' + str(i + 2)].value = ''
ws['J' + str(i + 2)].value = wordlist[i]['pos']
ws['K' + str(i + 2)].value = wordlist[i]['lemma']
try:
ws['L' + str(i + 2)].value = wordlist[i]['operation']
except KeyError:
ws['L' + str(i + 2)].value = ""
# ws = wb['重複削除&ソート'] # これはエラーになる
# ws.cell(row=2, column=2).value = '=SORT(UNIQUE(全リスト!B2:G10000))&""'
wb.save(export_file_path)
wb.close() #これは不要らしい
def create_menu(file_path):
print('保存処理中...')
import xlwings
excel = xlwings.App(visible=False)
wb = excel.books.open(file_path)
macro = wb.macro('addMenu')
macro()
wb.save()
wb.close()
excel.quit()
def create_button(file_path):
print('保存処理中...')
import xlwings
excel = xlwings.App(visible=False)
wb = excel.books.open(file_path)
macro = wb.macro('createButton')
macro()
wb.save()
wb.close()
excel.quit()
def export_xlsx_wings(wordlist):
import xlwings
xlwings.App(visible=False, spec=None, impl=None).screen_updating = False
wb = xlwings.Book('wordlist_templet.xlsm')
sheet = wb.sheets['sheet1']
for i in range(0, len(wordlist)):
sheet['B' + str(i + 2)].value = wordlist[i]['word']
sheet['C' + str(i + 2)].value = wordlist[i]['pos_m']
sheet['D' + str(i + 2)].value = wordlist[i]['phone']
sheet['E' + str(i + 2)].value = wordlist[i]['mean']
sheet['F' + str(i + 2)].value = wordlist[i]['identifier']
sheet['G' + str(i + 2)].value = wordlist[i]['page']
sheet['I' + str(i + 2)].value = wordlist[i]['original_word']
sheet['J' + str(i + 2)].value = wordlist[i]['pos']
sheet['K' + str(i + 2)].value = wordlist[i]['lemma']
try:
sheet['L' + str(i + 2)].value = wordlist[i]['operation']
except KeyError:
sheet['L' + str(i + 2)].value = ""
xlwings.screen_updating = True
# 下記でCCの説明を得る
# next((x for x in ref if x['PoS'] == 'CC'), None)['mean']
# 下記でwordlistの0番目の辞書データから'pos'に相当する日本語の説明を得る
# print(next((x for x in ref if x['PoS'] == wordlist[0]['pos']), None)['mean'])