def openspreadsheet( filename ): ext = filename.split('.',1)[1].lower() if( ext == 'xls'): return xlrd.open_workbook(filename,on_demand=True) # getsheet = xlrd.Book.sheet_by_name else: return odf.opendoc(filename)
def print_headings(filename): """ Print all <text:h> elements of an ODF-Text document. """ doc = ezodf2.opendoc(filename) if doc.doctype == 'odt': count = 0 for heading in doc.body.filter('Heading'): count += 1 level = heading.outline_level print("H {0:03d} {1} {2}".format(count, '>'*level, heading.plaintext())) print('done.\n') else: print('Need a text document to print headings.\n')
def main(): global doc, nsmap doc = ezodf2.opendoc("out/resume.odt") nsmap = doc.body.xmlnode.nsmap # work expeirence rows keep_work_exp_together() # references keep_table_together(doc.body.xmlnode.findall(".//text:p[@text:style-name='rststyle-refleft']", nsmap)[0]) # awards keep_table_together(doc.body.xmlnode.findall(".//text:p[@text:style-name='rststyle-dateleft']", nsmap)[0]) doc.save()
def testezodf2(): # open spreadsheet document # set strategy "all", "all_but_last", "all_less_maxcount' config.table_expand_strategy.set_strategy('all_less_maxcount',(3000,150)) doc = odf.opendoc(filename2) print("Spreadsheet contains %d sheets.\n" % len(doc.sheets)) for sheet in doc.sheets: print("Sheet name: '%s'" % sheet.name) print("Size of Sheet : (rows=%d, cols=%d)" % (sheet.nrows(), sheet.ncols()) ) print("-"*40) summarysheet = doc.sheets[0] #Sheet. #Cell.xmlnode mycells = summarysheet #for cells in mycells: # print(cells.value) return doc.sheets[0]
#!/usr/bin/env python #coding:utf-8 # Purpose: example insertcolumns.py # Created: 05.02.2011 # Copyright (C) 2011, Manfred Moitzi # License: MIT from __future__ import unicode_literals, print_function, division __author__ = "mozman <*****@*****.**>" import ezodf2 ods = ezodf2.opendoc('refsheet.ods') sheet = ods.sheets[0] sheet.insert_columns(5, 3) sheet.insert_rows(5, 3) for row in range(sheet.nrows()): for col in range(5, 8): content = '+COL' + str(col) sheet[row, col].set_value(content) for col in range(sheet.ncols()): for row in range(5, 8): content = '+ROW' + str(row) sheet[row, col].set_value(content) ods.save()
def import_ods(filename, glider=None): ods = ezodf.opendoc(filename) sheets = ods.sheets # Profiles -> map xvalues profiles = [Profile2D(profile) for profile in transpose_columns(sheets[3])] xvalues = sorted(profiles, key=lambda prof: prof.numpoints)[0].x_values # Use airfoil with maximum profilepoints for profile in profiles: profile.x_values = xvalues # Ballooning old : 1-8 > upper (prepend/append (0,0),(1,0)), 9-16 > lower (same + * (1,-1)) balloonings_temp = transpose_columns(sheets[4]) balloonings = [] for baloon in balloonings_temp: upper = [[0, 0]] + baloon[:7] + [[1, 0]] lower = [[0, 0]] + [[i[0], -1 * i[1]] for i in baloon[8:15]] + [[1, 0]] balloonings.append(BallooningBezier([upper, lower])) # Data data = {} datasheet = sheets[-1] assert isinstance(datasheet, ezodf.Sheet) for i in range(datasheet.nrows()): data[datasheet.get_cell([i, 0]).value] = datasheet.get_cell([i, 1]).value #print(data["GLEITZAHL"]) glider.data = data cells = [] main = sheets[0] x = y = z = span_last = 0. alpha2 = 0. thisrib = None # TODO: Glide -> DATAIMPORT for i in range(1, main.nrows()): line = [main.get_cell([i, j]).value for j in range(main.ncols())] if not line[0]: #print("leere zeile:", i, main.nrows()) break chord = line[1] # Rib-Chord span = line[2] # spanwise-length (flat) alpha1 = alpha2 # angle before the rib alpha2 += line[4] * numpy.pi / 180 # angle after the rib alpha = (span > 0) * (alpha1 + alpha2) * 0.5 + line[6] * numpy.pi / 180 # rib's angle x = line[3] # x-value -> front/back (ribwise) y += numpy.cos(alpha1) * (span - span_last) # y-value -> spanwise z -= numpy.sin(alpha1) * (span - span_last) # z-axis -> up/down aoa = line[5] * numpy.pi / 180 zrot = line[7] * numpy.pi / 180 span_last = span profile = merge(line[8], profiles) ballooning = merge(line[9], balloonings) lastrib = thisrib thisrib = Rib(profile, ballooning, numpy.array([x, y, z]), chord, alpha, aoa, zrot, data["GLEITZAHL"]) if i == 1 and y != 0: # Middle-cell #print("midrib!", y) lastrib = thisrib.copy() lastrib.mirror() if lastrib: cell = Cell(lastrib, thisrib, []) cell.name = "Cell_no"+str(i) cells.append(cell) if glider: glider.cells = cells glider.close_rib() return return cells
#!/usr/bin/env python #coding:utf-8 # Purpose: swap row/columns of a table # Created: 28.05.2012 # Copyright (C) 2012, Manfred Moitzi # License: MIT from __future__ import unicode_literals, print_function, division __author__ = "mozman <*****@*****.**>" import ezodf2 # open spreadsheet document doc = ezodf2.opendoc("big-test-table.ods") print("Spreadsheet contains %d sheets.\n" % len(doc.sheets)) for sheet in doc.sheets: print("Sheet name: '%s'" % sheet.name) print("Size of Sheet : (rows=%d, cols=%d)" % (sheet.nrows(), sheet.ncols()) ) print("-"*40) doc.save()
def import_ods(filename, glider=None): ods = ezodf.opendoc(filename) sheets = ods.sheets # Profiles -> map xvalues profiles = [Profile2D(profile) for profile in transpose_columns(sheets[3])] xvalues = sorted(profiles, key=lambda prof: prof.numpoints)[0].x_values # Use airfoil with maximum profilepoints for profile in profiles: profile.x_values = xvalues # Ballooning old : 1-8 > upper (prepend/append (0,0),(1,0)), 9-16 > lower (same + * (1,-1)) balloonings_temp = transpose_columns(sheets[4]) balloonings = [] for baloon in balloonings_temp: upper = [[0, 0]] + baloon[:7] + [[1, 0]] lower = [[0, 0]] + [[i[0], -1 * i[1]] for i in baloon[8:15]] + [[1, 0]] balloonings.append(BallooningBezier([upper, lower])) # Data data = {} datasheet = sheets[-1] assert isinstance(datasheet, ezodf.Sheet) for i in range(datasheet.nrows()): data[datasheet.get_cell([i, 0]).value] = datasheet.get_cell([i, 1]).value #print(data["GLEITZAHL"]) glider.data = data cells = [] main = sheets[0] x = y = z = span_last = 0. alpha2 = 0. thisrib = None # TODO: Glide -> DATAIMPORT for i in range(1, main.nrows()): line = [main.get_cell([i, j]).value for j in range(main.ncols())] if not line[0]: #print("leere zeile:", i, main.nrows()) break chord = line[1] # Rib-Chord span = line[2] # spanwise-length (flat) alpha1 = alpha2 # angle before the rib alpha2 += line[4] * numpy.pi / 180 # angle after the rib alpha = (span > 0) * (alpha1 + alpha2) * 0.5 + line[6] * numpy.pi / 180 # rib's angle x = line[3] # x-value -> front/back (ribwise) y += numpy.cos(alpha1) * (span - span_last) # y-value -> spanwise z -= numpy.sin(alpha1) * (span - span_last) # z-axis -> up/down aoa = line[5] * numpy.pi / 180 zrot = line[7] * numpy.pi / 180 span_last = span profile = merge(line[8], profiles) ballooning = merge(line[9], balloonings) lastrib = thisrib thisrib = Rib(profile, ballooning, numpy.array([x, y, z]), chord, alpha, aoa, zrot, data["GLEITZAHL"]) if i == 1 and y != 0: # Middle-cell #print("midrib!", y) lastrib = thisrib.copy() lastrib.mirror() if lastrib: cell = Cell(lastrib, thisrib, []) cell.name = "Cell_no"+str(i) cells.append(cell) if glider: glider.cells = cells glider.close_rib() glider.attachment_points = read_elements(sheets[2], "AHP", AttachmentPoint) glider.attachment_points_lower = get_lower_aufhaengepunkte(glider.data) for p in glider.attachment_points: p.force = numpy.array([0, 0, 1]) p.get_position(glider) glider.lines = tolist_lines(sheets[6], glider.attachment_points_lower, glider.attachment_points) glider.lines.calc_geo() glider.lines.calc_sag() return return cells
print sock file_path = settings.filepath filename = settings.filename start_row = 2 start_column = 1 global spreadsheet global sheets global table global rowcount global current_cell parent_id = 0 # open the ODS file spreadsheet = ezodf2.opendoc(file_path + filename) # assign the spreadsheet objects to a list sheets = spreadsheet.sheets #this function creates parent categories when needed def create_parents(category): global parent_id category_id = 0 category = re.sub(": |- ", ":", category) pieces = category.rsplit(":") for i in xrange(0, len(pieces),1): parent_id = search_category_on_oerp(pieces[i-1]) current_category = search_category_on_oerp(pieces[i]) if not current_category: category_id = create_category_on_oerp(pieces[i])