2015年8月14日金曜日

[Python][pyExcelerator]動作確認

次のデータが入った Excel ファイルを準備する
January February March April May June July August September October November December
tokyo 7.0 6.5 9.1 12.4 19.0 23.6 28.0 29.6 25.1 18.9 13.5 9.9
naha 16.8 18.3 19.9 21.2 23.8 26.7 28.7 28.9 28.0 25.7 21.4 18.1
sapporo -2.0 -3.2 -0.1 5.5 12.2 19.2 22.1 24.8 20.0 12.2 5.9 0.6
2 枚目の sheet, 3 枚目の sheet は空、Sheet 名は Sheet2, Sheet3
test00.py
# -*- coding:utf-8 -*-
import pyExcelerator

xlsSheets = pyExcelerator.parse_xls("test00.xls")
# (Sheet 名, シートの中身) というリストで格納される
print xlsSheets
for sheetName, values in xlsSheets:
    print "Sheet name: %s" % (sheetName)
    print "values.keys(): ", sorted(values.keys())
    row = ""
    for rowIdx, colIdx in sorted(values.keys()):
        v = values[(rowIdx, colIdx)]
        print "(%d, %d): %s" % (rowIdx, colIdx, v)

実行結果
> python test00.py
[(u'Sheet1', {(1, 3): 9.1, (3, 0): u'sapporo', (2, 8): 28.9, (3, 11): 5.9, (0, 7): u'July', (1, 6): 23.6, (0, 10): u'October', (2, 10): 25.7, (3, 7): 22.1, (0,3): u'March', (1, 11): 13.5, (2, 5): 23.8, (1, 2): 6.5, (3, 3): -0.1, (2, 9): 28.0, (2, 0): u'naha', (3, 10): 12.2, (1, 5): 19.0, (0, 11): u'November', (3, 6):19.2, (0, 4): u'April', (1, 10): 18.9, (1, 1): 7.0, (2, 7): 28.7, (3, 2): -3.2,(2, 6): 26.7, (2, 2): 18.3, (1, 4): 12.4, (0, 12): u'December', (2, 1): 16.8, (3, 9): 20.0, (0, 5): u'May', (1, 9): 25.1, (1, 0): u'tokyo', (0, 8): u'August', (3, 5): 12.2, (0, 1): u'January', (3, 12): 0.6, (1, 12): 9.9, (3, 1): -2.0, (2, 11): 21.4, (2, 4): 21.2, (3, 8): 24.8, (0, 6): u'June', (1, 8): 29.6, (1, 7): 28.0, (0, 9): u'September', (2, 3): 19.9, (3, 4): 5.5, (0, 2): u'February', (2, 12): 18.1}), (u'Sheet2', {}), (u'Sheet3', {})]
Sheet name: Sheet1
values.keys():  [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (0, 9), (0, 10), (0, 11), (0, 12), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1,5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (1, 12), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), (2, 10), (2, 11), (2, 12), (3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (3, 11), (3, 12)]
(0, 1): January
(0, 2): February
(0, 3): March
(0, 4): April
(0, 5): May
(0, 6): June
(0, 7): July
(0, 8): August
(0, 9): September
(0, 10): October
(0, 11): November
(0, 12): December
(1, 0): tokyo
(1, 1): 7.0
(1, 2): 6.5
(1, 3): 9.1
(1, 4): 12.4
(1, 5): 19.0
(1, 6): 23.6
(1, 7): 28.0
(1, 8): 29.6
(1, 9): 25.1
(1, 10): 18.9
(1, 11): 13.5
(1, 12): 9.9
(2, 0): naha
(2, 1): 16.8
(2, 2): 18.3
(2, 3): 19.9
(2, 4): 21.2
(2, 5): 23.8
(2, 6): 26.7
(2, 7): 28.7
(2, 8): 28.9
(2, 9): 28.0
(2, 10): 25.7
(2, 11): 21.4
(2, 12): 18.1
(3, 0): sapporo
(3, 1): -2.0
(3, 2): -3.2
(3, 3): -0.1
(3, 4): 5.5
(3, 5): 12.2
(3, 6): 19.2
(3, 7): 22.1
(3, 8): 24.8
(3, 9): 20.0
(3, 10): 12.2
(3, 11): 5.9
(3, 12): 0.6
Sheet name: Sheet2
values.keys():  []
Sheet name: Sheet3
values.keys():  []

0 件のコメント:

コメントを投稿