Excelファイルからデータの記述されているセルを読み出して、その一覧を表示するためのPython3のプログラム。
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
#!/usr/bin/python3 | |
# | |
# See https://pandanote.info/?p=7224 for details. | |
# | |
import io | |
import sys | |
import os | |
import argparse | |
import openpyxl | |
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') | |
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | |
parser = argparse.ArgumentParser(description='Command line option of dumpxlsxposandvalues.py') | |
parser.add_argument('-i','--input-file', type=str, help='Name of an input file.',required=True) | |
args = parser.parse_args() | |
print(args) | |
params = vars(args) | |
input_file = params['input_file'] | |
if os.path.isfile(input_file) == False: | |
print("{0:s} is not found.".format(input_file)) | |
sys.exit(1) | |
wb = openpyxl.load_workbook(input_file) | |
for ws in wb: | |
print("{0:s}".format(ws.title)) | |
for row in ws.rows: | |
for cell in row: | |
if cell.value != None: | |
print("{0:s} {1:d},{2:d} {3:s}".format(cell.coordinate, cell.row, cell.column, cell.value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment