I extended last project module, and made a CLI tool to translate the entire row into English.
Output Example:
These questions in Japanese becomes…
English.
Here is the code:
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 |
import openpyxl import google_clouds TARGET_COLUMN = 'C' if len(sys.argv) != 2: print(f"Usage: {sys.argv[0]} 'original excel file'") sys.exit(0) print('opening workbook') workbook = sys.argv[1] wb = openpyxl.load_workbook(workbook) sheets = wb.sheetnames target = wb[sheets[0]] # target = wb.copy_worksheet(original) print('reading rows...') for row in range(2, len(target[TARGET_COLUMN]) + 1): original_text = target[TARGET_COLUMN + str(row)].value if original_text is not None and len(original_text) > 0: target[TARGET_COLUMN + str(row)].value = google_clouds.get_translate(original_text) wb.save('Translated_' + workbook.split('/')[-1]) print('done...') |