Skip to content

Instantly share code, notes, and snippets.

@isann
Created June 19, 2012 05:51
Show Gist options
  • Save isann/2952503 to your computer and use it in GitHub Desktop.
Save isann/2952503 to your computer and use it in GitHub Desktop.
pythonでexcelのデータを読み込む
# -*- coding: utf-8 -*-
import random
from openpyxl import load_workbook
__author__ = 'isann'
def out(max, min):
if max is 0:
print(min)
else:
print(max)
class DataModel():
min = None
max = None
col_type = None
def main():
# print xlrd.__VERSION__
# book = xlrd.open_workbook('../../../data/INPUT.xls')
# print(book.nsheets)
# print(book.sheet_by_index(0).name)
# print(book.sheet_by_index(0).ncols)
# print(book.sheet_by_index(0).nrows)
# print(book.sheet_by_index(0).cell(7, 1).value)
TYPE_ASCII_SU = 1
TYPE_ASCII_EISU = 0
wb = load_workbook('../../../data/INPUT.xlsx')
sheet_ranges = wb.get_sheet_by_name(name=u'R3用')
# print(sheet_ranges._cells)
data_models = []
for i in range(8, 52):
data_model = DataModel()
# defined_name = 'B'
defined_digit = 'G'
defined_type = 'F'
# print sheet_ranges.cell(defined_name + str(i)).value
keta = sheet_ranges.cell(defined_digit + str(i)).value
if type(keta) == int:
data_model.min = keta
else:
data_model.min = keta[0:1]
data_model.max = keta[2:]
col_type = sheet_ranges.cell(defined_type + str(i)).value
if col_type == u'半角英数':
data_model.col_type= TYPE_ASCII_EISU
else:
data_model.col_type = TYPE_ASCII_SU
data_models.append(data_model)
for data_model in data_models:
print('---------------------------------------------------------------')
print(data_model.col_type)
print(data_model.min)
print(data_model.max)
def random_ascii_char(cnt=1):
"""
this method generate ascii chars.
@param cnt generate num of chars
@return ascii string
"""
charmap = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ]
chars = ''
for i in range(0, cnt):
chars += charmap[random.randint(0, len(charmap)-1)]
return chars
if __name__ == "__main__":
# main()
# print(len(str(1)))
print(random_ascii_char(100))
print(len(random_ascii_char(100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment