def verif(nom_feuille_pond, nom_feuille_stat, nom_feuille_res, nom_feuille_qemp, nom_feuille_qnorm, nom_feuille_sort, nom_feuille_Ftriang, nom_feuille_qtriang, nom_feuille_err_ve, nom_feuille_err_inv, nom_feuille_indice): """ Verifie que le nom des feuilles resultats n'existe pas. supprime les feuilles intermediaires et cree les feuilles nom_feuille_res et nom_feuille_pond """ name_list = [ nom_feuille_pond, nom_feuille_stat, nom_feuille_res + "_emp", nom_feuille_res + "_norm", nom_feuille_res + "_triang", nom_feuille_qemp, nom_feuille_qnorm, nom_feuille_sort, nom_feuille_Ftriang, nom_feuille_qtriang, nom_feuille_err_ve, nom_feuille_err_inv, nom_feuille_indice, "details" ] for ws in initialisation.Worksheets: if ws.Name == nom_feuille_res: rep = message_box( 'Attention...', 'Result\'s worksheet already ' 'exists!\ If you continue, this one will be destroyed.\ Would you like to go on?\n\ If you want to keep this previous results,\ rename the SSWD_result worksheet.', 4) if rep == 7 or not rep: sys.exit(0) else: del initialisation.Worksheets[ws.Name] else: if ws.Name in name_list: del initialisation.Worksheets[ws.Name] for name_str in name_list: initialisation.Worksheets[name_str] = Worksheet(name=name_str)
def generate_brief_excel(shipments): # Initializie the workbook workbook = Workbook(write_only=False) worksheets = [] for shipment in shipments: i = shipment.index worksheet = Worksheet(workbook.create_sheet("Shipment%d" % (i + 1), i)) for index, box in enumerate(shipment.boxes): worksheet.write([index + 1, box.box_index, box.name]) workbook.save(OUPTPUT_FOLDER_PATH + '/shipments_brief.xlsx')
def __init__(self, notebook, edit_only=False): gtk.TextBuffer.__init__(self) self.worksheet = Worksheet(notebook, edit_only) self.worksheet.sig_text_inserted.connect(self.on_text_inserted) self.worksheet.sig_text_deleted.connect(self.on_text_deleted) self.worksheet.sig_lines_inserted.connect(self.on_lines_inserted) self.worksheet.sig_lines_deleted.connect(self.on_lines_deleted) self.worksheet.sig_chunk_inserted.connect(self.on_chunk_inserted) self.worksheet.sig_chunk_changed.connect(self.on_chunk_changed) self.worksheet.sig_chunk_deleted.connect(self.on_chunk_deleted) self.worksheet.sig_chunk_status_changed.connect( self.on_chunk_status_changed) self.worksheet.sig_chunk_results_changed.connect( self.on_chunk_results_changed) self.worksheet.sig_place_cursor.connect(self.on_place_cursor) style = DEFAULT_STYLE # If the last line of the buffer is empty, then there's no way to set a # paragraph style for it - this means that we can't reliably make # chunk.set_pixels_below() work for the last line in the buffer. # So, what we do is override pixels_below_lines for the whole buffer, # enabling gtk.TextView.set_pixels_below_lines() to be used for this. self.__whole_buffer_tag = self.create_tag(pixels_below_lines=0) self.__result_tag = style.get_tag(self, 'result') # Bit of a cheat - don't want to add these to StyleSpec, since they are editor specific. # If the spec was shared by an alias, this would do unexpected things. self.__result_tag.set_properties(wrap_mode=gtk.WRAP_WORD, editable=False) self.__warning_tag = style.get_tag(self, 'warning') self.__error_tag = style.get_tag(self, 'error') self.__error_line_tag = style.get_tag(self, 'error-line') # We want the recompute tag to have higher priority, so we fetch it after result_tag # which will result in it being defined second self.__status_tags = style.get_tag(self, 'recompute') self.__comment_tag = style.get_tag(self, 'comment') self.__help_tag = style.get_tag(self, 'help') self.__bold_tag = self.create_tag(weight=pango.WEIGHT_BOLD) self.__fontify_tags = {} for subject in style.specs: if isinstance(subject, int): # A token type self.__fontify_tags[subject] = style.get_tag(self, subject) self.__line_marks = [ self.create_mark(None, self.get_start_iter(), True) ] self.__line_marks[0].line = 0 self.__in_modification_count = 0 self.__have_pair = False self.__pair_mark = self.create_mark(None, self.get_start_iter(), True)
def init(): # Initialize the output directory h.create_dir(OUPTPUT_FOLDER_PATH) # Initializie the workbook workbook = Workbook(write_only=False) worksheets = [] shipments = [] for i in xrange(SHIPMENTS): worksheets.append( Worksheet(workbook.create_sheet("Shipment%d" % (i + 1), i))) shipments.append(Shipment(i)) return (workbook, worksheets, shipments)
def worksheet_from_excel(excel_sheet): worksheet = Worksheet() for col in range(excel_sheet.ncols): for row in range(excel_sheet.nrows): cell = excel_sheet.cell(row, col) if cell.ctype == XL_CELL_ERROR: formula = '=%s' % (error_text_from_code[cell.value], ) elif cell.ctype == XL_CELL_DATE: formula = '=DateTime(%s, %s, %s, %s, %s, %s)' % xldate_as_tuple( cell.value, excel_sheet.book.datemode) else: formula = unicode(excel_sheet.cell(row, col).value) worksheet[col + 1, row + 1].formula = formula return worksheet
def extractData(self): # self.reviewerData = {} # self.reviewerData['r1'] = {} # self.reviewerData['r2'] = {} # self.contentCreatorData = {} for i in tqdm(range(maxsheets)): try: data = self.__wkb.get_worksheet(i).get_all_values() wks = Worksheet(data, Workbook.__contentCreatorData, Workbook.__reviewerData) wks.updateCreatorDict() wks.updateReviewerDict() except Exception as e: logging.warn( str(e) + f" for sheet{i} in Workbook: {self.wkbname}")
def get_sheet(self, idx, rels=False): if isinstance(idx, basestring): idx = self.sheets.index(idx) + 1 if idx < 1 or idx > len(self.sheets): raise IndexError('sheet index out of range') temp = TemporaryFile() with self._zf.open('xl/worksheets/sheet{}.bin'.format(idx), 'r') as zf: temp.write(zf.read()) temp.seek(0, os.SEEK_SET) if rels: rels_temp = TemporaryFile() with self._zf.open('xl/worksheets/_rels/sheet{}.bin.rels'.format(idx), 'r') as zf: rels_temp.write(zf.read()) rels_temp.seek(0, os.SEEK_SET) else: rels_temp = None return Worksheet(fp=temp, rels_fp=rels_temp, stringtable=self.stringtable)