Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Created January 23, 2021 07:41
Show Gist options
  • Save pandanote-info/274d354e902a5af2049117279e8298f2 to your computer and use it in GitHub Desktop.
Save pandanote-info/274d354e902a5af2049117279e8298f2 to your computer and use it in GitHub Desktop.
Excelファイルからデータの記述されているセルを読み出して、その一覧を表示するためのPython3のプログラム。
#!/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