def cover_search_2_images(path): cover_search = OpenExcel(path) if cover_search.read( "A1") == "ENGLISH HERITAGE - NATIONAL MONUMENTS RECORD": return type_one_cover_search_2_images(path) elif cover_search.read("B13") == "Sortie number": return type_two_cover_search_2_images(path) elif cover_search.read("B10") == "Sortie number": return type_two_cover_search_2_images(path) else: raise UnknownFormatError
class XLSXOpenExcel(IO): def read(self, filename): self.sheet = OpenExcel(filename) self.row_count = self.sheet.read().nrows self.col_count = self.sheet.read().ncols def _float_to_string(self, sheet, col): values = sheet.read(col) if values[0] in self.column_names: return values for i, value in enumerate(values): if isinstance(value, float): values[i] = str(int(value)) elif isinstance(value, unicode): values[i] = str(value) return values def column_heading_letter(self, heading_name): for letter in self.column_letters(): if self.sheet.read(letter)[0] == heading_name: return letter @property def column_names(self): return tuple([ col[0] for col in [ self.sheet.sheets.col_values(i) for i in range(self.sheet.getCols()) ] ]) @property def column_letters(self): _letters = letters[26:] num_cols = self.sheet.read().ncols double_letters, triple_letters = ([], ) * 2 for l in _letters: for m in _letters: double_letters += [l + m] for l in _letters: for m in _letters: for n in _letters: triple_letters += [l + m + n] _letters = list(_letters) + double_letters + triple_letters res = zip(_letters, range(1, num_cols)) return tuple([r[0] for r in res])
def type_two_cover_search_2_images(path): cover_search = OpenExcel(path) row = 15 done = False images = [] while not done: row_data = cover_search.read(row) if row_data[1] == "": done = True else: new_image = AerialImage(row_data[1], int(row_data[2]), int(row_data[4]), row_data[6], int(row_data[8]), row_data[9], row_data[12], int(row_data[14]), int(row_data[15]), row_data[16]) images.append(new_image) row += 1 return images
def type_one_cover_search_2_images(path): cover_search = OpenExcel(path) starts = [] for r in range(cover_search.getRows()): pass # Todo row = 15 done = False images = [] while not done: row_data = cover_search.read(row) if row_data[1] == "": done = True else: new_image = AerialImage(row_data[1], int(row_data[2]), int(row_data[4]), row_data[6], int(row_data[8]), row_data[9], row_data[12], int(row_data[14]), int(row_data[15]), row_data[16]) images.append(new_image) row += 1 return images
def analise_cover_search(path): random_ref = hex(random.randint(1, 4294967296)).upper().strip("0X") cover_search = OpenExcel(path) data = cover_search.read() # Find Table Starts found_start = False table_starts = [] sheet_width = cover_search.getCols() sheet_height = cover_search.getRows() for c in range(sheet_width): for r in range(sheet_height): cell_data = cover_search.read("{}{}".format(ALPHABET[c], r + 1)) if ("SORTIE" in str(cell_data).upper()) and ( "TOTAL" not in str(cell_data).upper()): found_start = True table_starts.append((c, r)) if found_start: break else: pass items = [] for start in table_starts: headers = [] # To be list of (column, "header text") current_row = start[1] data_started = False while not data_started: current_row += 1 first_cell_address = "{}{}".format(ALPHABET[start[0]], current_row + 1) try: cell_data = cover_search.read(first_cell_address) except IndexError: print("Failed at: {}".format(first_cell_address)) raise if cell_data.count("/") > 0: data_started = True else: pass empty_cols = [] for c in range(sheet_width): cell_data = cover_search.read("{}{}".format( ALPHABET[c], current_row + 1)) if cell_data == "": empty_cols.append(c) else: headers.append([ALPHABET[c], ""]) for c, h in enumerate(headers): cell_data = cover_search.read("{}{}".format(h[0], start[1] + 1)) if cell_data == "": headers[c][1] = "{}:{}".format(random_ref, [c][0]) else: headers[c][1] = cell_data.strip() data_started = False data_finished = False current_row = start[1] + 1 while not data_finished: first_cell_address = "{}{}".format(headers[0][0], current_row + 1) try: cell_data = cover_search.read(first_cell_address) except IndexError: data_finished = True break if cell_data.count("/") > 0: data_started = True else: pass new_item = dict() for i, h in enumerate(headers): cell_address = "{}{}".format(h[0], current_row + 1) cell_data = cover_search.read(cell_address) if not data_started: if cell_data != "": headers[i][1] += " {}".format(cell_data) else: pass else: if (i == 0) and (cell_data.count("/") < 1): data_finished = True break else: new_item[h[1]] = cell_data if new_item == dict(): pass else: new_item["originating_file"] = path items.append(new_item) current_row += 1 return items
#!/usr/bin/env python from excel import OpenExcel f = OpenExcel('namesdb.xls') print f.read('A') # read 'A' row print f.read('B') print "{} is gender {}".format(f.read('A2'), f.read('B2'))
#!/usr/bin/python from excel import OpenExcel f = OpenExcel('namesdb.xls') print f.read('A') print f.read('B') print f.read('A4')
def read(self, filename): self.sheet = OpenExcel(filename) self.row_count = self.sheet.read().nrows self.col_count = self.sheet.read().ncols
#!/usr/bin/python from excel import OpenExcel f = OpenExcel('names_db.xls') print f.read('A') print f.read('B') print "{} is a {}".format(f.read('A4'), f.read('B4'))
from excel import OpenExcel f = OpenExcel('test.xls') class Line(): def __init__(self, weight, layout, deltaX, deltaY, length, startX, startY, corner): self.weight = weight self.layout = layout self.deltaX = deltaX self.deltaY = deltaY self.length = length self.startX = startX self.startY = startY self.corner = corner class Cirle(): def __init__(self, weight, diameter, layout, coordinateX, coordinateY): self.weight = weight self.layout = layout self.diameter = diameter self.coordinateX = coordinateX self.coordinateY = coordinateY class Text(): def __init__(self, layout, coordinateX, coordinateY, height, value): self.layout = layout self.coordinateX = coordinateX
#!/usr/bin/python from excel import OpenExcel f = OpenExcel('names.xls') print f.read('A') print "my name is {} and my gender is {}".format(f.read('A3'), f.read('B3'))
#!/usr/bin/env python from excel import OpenExcel f = OpenExcel('names.xls') print f.read('A') print f.read('B') name=f.read('A3') gender=f.read('B3') print "my name is {} and gender is {}".format(name,gender)
def read_xls(xls_file): from excel import OpenExcel xls = OpenExcel(xls_file) nrows = len(xls.read('A')) for irow in range(1, nrows + 1): yield xls.read(irow)
from excel import OpenExcel f = OpenExcel('Zeszyt1.xls') f.read() # read all x = f.read('A') # read 'A' row print(x) f.read(1) # f.read('1'), read '1' column f.read('A5') # read 'A5' position
#!/bin/python3 from excel import OpenExcel fh = OpenExcel("/home/eddy/Downloads/financial_sample.xlsx") print(fh.read("17B"))
#!/usr/bin/python from excel import OpenExcel f = OpenExcel('namesdb.xls') #name = raw_input("please enter the name of the student:") print f.read('A') # read 'A' row print f.read('A7'), f.read('B7') # read 'A' row
# A package contains all the files you need for a module. # # Modules are Python code libraries you can include in your project. # Check if PIP is Installed # pip --version # Download a Package # Downloading a package is very easy. # # Open the command line interface and tell PIP to download the package you want. # # Navigate your command line to the location of Python's script directory, and type the following: pip install Camelcase - This will install the camelcase package """ import camelcase c = camelcase.CamelCase() d = "hello world" print(c.hump(d)) from humps.camel import case print(case('madhu 2mallidi hyderabad')) from excel import OpenExcel f = OpenExcel('TEST.xlsx') print(f.read('A')) # read 'A' row
#!/usr/bin/python # https://github.com/tuxfux-hlp/Python-examples/blob/master/files/my_read.py from excel import OpenExcel f = OpenExcel('names.xls') print f.read('A') print f.read('B') print "{} is a {}".format(f.read('A8'), f.read('B8'))
import math import numpy as np from scipy import stats import matplotlib.pyplot as plt from excel import OpenExcel NAZWA_PLIKU = 'dane-covid-usa.xlsx' print('Obliczanie regresji liniowej,') print('dane są czytane z pliku', NAZWA_PLIKU) rozszerzenie = NAZWA_PLIKU[-5:].lower() if rozszerzenie == '.xlsx': plik = OpenExcel(NAZWA_PLIKU) x = plik.read('A') y = plik.read('B') for i in range(len(y)): if type(y[i]) == str: y[i] = float(y[i].replace('\xa0', '')) x = np.array(x) y = np.array(np.log10(y)) elif rozszerzenie == '.txt': x, y = np.loadtxt(NAZWA_PLIKU, unpack=True) else: raise RuntimeError('nieznany typ pliku') n = len(x)