def show(bk, nshow=65535, printit=1): bk_header(bk) if 0: rclist = xlrd.sheet.rc_stats.items() rclist = sorted(rclist) print("rc stats") for k, v in rclist: print("0x%04x %7d" % (k, v)) if options.onesheet: try: shx = int(options.onesheet) except ValueError: shx = bk.sheet_by_name(options.onesheet).number shxrange = [shx] else: shxrange = range(bk.nsheets) # print("shxrange", list(shxrange)) for shx in shxrange: sh = bk.sheet_by_index(shx) nrows, ncols = sh.nrows, sh.ncols colrange = range(ncols) anshow = min(nshow, nrows) print("sheet %d: name = %s; nrows = %d; ncols = %d" % (shx, REPR(sh.name), sh.nrows, sh.ncols)) if nrows and ncols: # Beat the bounds for rowx in xrange(nrows): nc = sh.row_len(rowx) if nc: sh.row_types(rowx)[nc - 1] sh.row_values(rowx)[nc - 1] sh.cell(rowx, nc - 1) for rowx in xrange(anshow - 1): if not printit and rowx % 10000 == 1 and rowx > 1: print("done %d rows" % (rowx - 1, )) show_row(bk, sh, rowx, colrange, printit) if anshow and nrows: show_row(bk, sh, nrows - 1, colrange, printit) print() if bk.on_demand: bk.unload_sheet(shx)
origin_row.append('\n'.join( [x for x in timelist if len(x) > 3])) f.write("%d\n" % sum1) if rx == 2: form_row.append(u"总和") else: form_row.append(sum1) form.append(form_row) origin_form.append(origin_row) return "out.csv", form, origin_form if __name__ == '__main__': book = xlrd.open_workbook('./data.xls') print "%r" % REPR(book.sheet_names()) print book.biff_version, book.codepage, book.encoding sheet = book.sheet_by_index(0) print sheet.ncols, sheet.nrows form = [] with open('out.csv', 'w') as f: for rx in xrange(2, sheet.nrows): form_row = [] for cx in xrange(sheet.ncols): cell = sheet.cell_value(rx, cx) if cx < 2 or rx < 3: print "row: %d col: %d val: %s" % (rx, cx, cell.encode("GBK")) f.write(cell.encode("GBK"))