Last active
August 29, 2015 14:23
-
-
Save denkiwakame/f3920915744e08eca154 to your computer and use it in GitHub Desktop.
xlrd
This file contains hidden or 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
from types import * | |
import xlrd | |
def value2str(val,encoding='cp932'): # or utf-8 | |
if type(val) == FloatType: return str(val) | |
if type(val) == UnicodeType: return val.encode(encoding) | |
if type(val) == StringType: return val | |
raise TypeError("cannot convert '%s' type:%s to string" % (val,type(val))) | |
def xlrdrow2str(xlrd_row, delim=","): | |
return delim.join([ value2str(cell.value) for cell in xlrd_row ]) | |
xlwoorkbook = xlrd.open_workbook('sample.xlsx') | |
xlsheet = xlwoorkbook.sheet_by_index(0) | |
nrow = xlsheet.nrows | |
for row_idx in range(nrow): | |
row = xlsheet.row(row_idx) | |
print xlrdrow2str(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment