Skip to content

Instantly share code, notes, and snippets.

@kubotama
Last active October 2, 2017 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubotama/ffd2f287dced63d87e77292732ad957d to your computer and use it in GitHub Desktop.
Save kubotama/ffd2f287dced63d87e77292732ad957d to your computer and use it in GitHub Desktop.
PythonでExcellのセルを参照する方法による値の違いを確認
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