Last active
October 2, 2017 04:58
-
-
Save kubotama/ffd2f287dced63d87e77292732ad957d to your computer and use it in GitHub Desktop.
PythonでExcellのセルを参照する方法による値の違いを確認
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 os | |
import win32com.client | |
xlsx = win32com.client.Dispatch('Excel.Application') | |
book = xlsx.Workbooks.Open(os.path.abspath('サンプルデータ.xlsx')) | |
sheet = book.Worksheets(1) | |
row = 2 | |
while 1: | |
cell = sheet.Cells(row, 3) | |
if sheet.Cells(row,1).value is None: | |
break | |
print('{} {}'.format(sheet.Cells(row,1).text, sheet.Cells(row,2).text)) | |
print('str: {} {}'.format(str(cell), type(str(cell)))) | |
print('value: {} {}'.format(cell.value, type(cell.value))) | |
print('value2: {} {}'.format(cell.value2, type(cell.value2))) | |
print('text: {} {}'.format(cell.text, type(cell.text))) | |
print('formula: {} {}'.format(cell.formula, type(cell.formula))) | |
print('\n') | |
row = row+1 | |
book.Close() | |
xlsx.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment