Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def xls_wrk(filename):
- #open file
- rb = open_workbook(filename)
- #set active sheet
- rs = rb.sheet_by_index(0)
- #make instance for xlsutils
- wb = copy(rb)
- ws = wb.get_sheet(0)
- rows = rs.nrows
- cols = rs.ncols
- #iterate and prepare format for SQL db tables
- wb = copy(rb)
- for row_idx in range (0,rows):
- for col_idx in range (0,cols):
- cell=rs.cell(row_idx,col_idx)
- clval = cell.value
- cltp = cell.ctype
- ws = wb.get_sheet(0)
- if cltp == xlrd.XL_CELL_BLANK:
- clval ="xy"
- ws.write(row_idx,col_idx,"xy")
- elif cltp == xlrd.XLDateError:
- date_format = XFStyle()
- date_format.num_format_str = 'dd/MM/yyyy'
- clval = '01/01/2018'
- ws.write(row_idx,col_idx, '01/01/2018', date_format)
- elif cltp == xlrd.XL_CELL_EMPTY:
- clval="XYU"
- ws.write(row_idx,col_idx,"xy")
- elif cltp == xlrd.XL_CELL_NUMBER:
- if clval < 0:
- clval=0
- ws.write(row_idx,col_idx,0)
- elif cltp == xlrd.XL_CELL_TEXT:
- clval = ftfy.fix_text(clval)
- ws.write(row_idx,col_idx, ftfy.fix_text(clval))
- elif clval == -693594:
- date_format = XFStyle()
- date_format.num_format_str = 'dd/MM/yyyy'
- clval='01/01/2018'
- ws.write(row_idx, col_idx,'01/01/2018',date_format)
- #print (row_idx,col_idx)
- save(wb,'abbcards_2.xls')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement