Last active
September 5, 2017 03:11
-
-
Save lili668668/d12e8a766b11eaf872e66317a0450dd9 to your computer and use it in GitHub Desktop.
將 kktix 的 csv 裡的檔案連結加工,讓 Google sheet 可以直接觀看圖片,方便檢驗身分
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import argparse | |
# 使用 Python3 | |
# python3 add_image.py 檔案路徑 | |
URL_ROW_NAME = "聯絡人 學生資格資料" | |
parser = argparse.ArgumentParser(description="Input the csv file path.") | |
parser.add_argument('file_path', metavar="file path", type=str, nargs=1, help="the kktix csv local file path") | |
args = parser.parse_args() | |
file_path = args.file_path[0] | |
with open(file_path, newline="", encoding="utf-8") as csvfile: | |
new_file_path = file_path.replace(".csv", "_new.csv") | |
with open(new_file_path, "w", newline="", encoding="utf-8") as new_csvfile: | |
reader = csv.DictReader(csvfile) | |
fieldnames = reader.fieldnames | |
writer = csv.DictWriter(new_csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
for row in reader: | |
row[URL_ROW_NAME] = '=image("' + row[URL_ROW_NAME] + '")' | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment