def show(bk, nshow=65535, printit=1):
     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)
     for shx in shxrange:
         sh = bk.sheet_by_index(shx)
         nrows, ncols = sh.nrows, sh.ncols
         colrange = range(ncols)
         print(json.dumps([ "sheet", {
             "index": shx,
             "name": sh.name,
             "rows": sh.nrows,
             "cols": sh.ncols,
             "visibility": sh.visibility
         }]))
         if nrows and ncols:
             # Beat the bounds
             for rowx in xrange(nrows):
                 nc = sh.row_len(rowx)
                 if nc:
                     _junk = sh.row_types(rowx)[nc-1]
                     _junk = sh.row_values(rowx)[nc-1]
                     _junk = sh.cell(rowx, nc-1)
         for rowx in xrange(nrows-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 nrows:
             show_row(bk, sh, nrows-1, colrange, printit)
         if bk.on_demand: bk.unload_sheet(shx)
Beispiel #2
0
 def print_labels(sh, labs, title):
     if not labs:return
     for rlo, rhi, clo, chi in labs:
         print("%s label range %s:%s contains:"
             % (title, xlrd.cellname(rlo, clo), xlrd.cellname(rhi-1, chi-1)))
         for rx in xrange(rlo, rhi):
             for cx in xrange(clo, chi):
                 print("    %s: %r" % (xlrd.cellname(rx, cx), sh.cell_value(rx, cx)))
Beispiel #3
0
 def count_xfs(bk):
     bk_header(bk)
     for shx in range(bk.nsheets):
         sh = bk.sheet_by_index(shx)
         nrows, ncols = sh.nrows, sh.ncols
         print("sheet %d: name = %r; nrows = %d; ncols = %d" %
             (shx, sh.name, sh.nrows, sh.ncols))
         # Access all xfindexes to force gathering stats
         type_stats = [0, 0, 0, 0, 0, 0, 0]
         for rowx in xrange(nrows):
             for colx in xrange(sh.row_len(rowx)):
                 xfx = sh.cell_xf_index(rowx, colx)
                 assert xfx >= 0
                 cty = sh.cell_type(rowx, colx)
                 type_stats[cty] += 1
         print("XF stats", sh._xf_index_stats)
         print("type stats", type_stats)
         print()
         if bk.on_demand: bk.unload_sheet(shx)
Beispiel #4
0
 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:
                     _junk = sh.row_types(rowx)[nc-1]
                     _junk = sh.row_values(rowx)[nc-1]
                     _junk = 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)
 def test_tidy_dimensions(self):
     book = xlrd.open_workbook(from_this_dir("merged_cells.xlsx"))
     for sheet in book.sheets():
         for rowx in xrange(sheet.nrows):
             self.assertEqual(sheet.row_len(rowx), sheet.ncols)
Beispiel #6
0
 def show_fonts(bk):
     print("Fonts:")
     for x in xrange(len(bk.font_list)):
         font = bk.font_list[x]
         font.dump(header='== Index %d ==' % x, indent=4)
 def show_fonts(bk):
     print("Fonts:")
     for x in xrange(len(bk.font_list)):
         font = bk.font_list[x]
         font.dump(header='== Index %d ==' % x, indent=4)
tup = ("Fishing 101", "Hunting 101", "Gathering 101")
# records
Person = Record.create_type("Person", "name", "email_address")
Student = Person.extend_type("Student", "courses_read", "graduation_date", graduation_date=None)
karan_student = Student("Karan Sahu", "*****@*****.**", ["Calculus", "Comsci"])

# [::-1]
print("::-1 example:")
print(NaturePlaces[::-1])

# range and xrange
print("xrange example:")
for x in range(1, 3, 1):
    print(x)

for x in xrange(1, 3, 1):
    print(x)
# append
print("append array example")
print(Animals)
Animals.append("Elaphant")
print(Animals)
#append in numpy array
print("numpy example")
print(["Dragon", "Lion", "Trex"])

sc = np.append(["UTA", "UTD", "UGA"], ["UT"])
print(sc)

#split
print("split example:")