def __tester_to_linked_list(): xlsx_test = 'test_to_linked_list.xlsx' excel = Excel(xlsx_test) linked_list_test = excel.to_linked_list() excel.close() li_1 = ['Programming Language', 'B'] li_2 = ['Programming Language', 'Html', 'A'] li_3 = ['Programming Language', 'Html', 'Basic', 'C'] linked_list_true = [li_1, li_2, li_3] p0 = linked_list_test == linked_list_true u_tester.run(p0)
def __get_li_rows(self): """ ======================================================================== Description: Return Linked List of Rows and Columns from Excel. ======================================================================== Return: List (Rows) of List (Cols) of Str (Values). ======================================================================== """ xlsx = os.path.join(self.path_myq, 'topics.xlsx') excel = Excel(xlsx) li_rows = excel.to_linked_list(self.fr, self.fc) excel.close() return li_rows
def __load_qs(self, xlsx_qs, topic): """ ======================================================================== Description: Load Questions from Excel into Dictionary of {str (Qid) -> Quest (Question} ======================================================================== Arguments: ------------------------------------------------------------------------ 1. xlsx_qs : str (Path to Excel-Question File) 2. topic : Topic Class (of the Excel-Question File). ======================================================================== """ assert type(xlsx_qs) == str assert type(topic) == Topic excel = Excel(xlsx_qs) row = self.fr while True: qid = self.__get_qid(excel, row, topic) # Break on EOF if not qid: break is_valid = self.__get_is_valid(excel, row) # Continue on invalid Question if not is_valid: row += 1 continue priority = topic.priority + self.__get_priority(excel, row) question = self.__get_question(excel, row) ans_true = self.__get_ans_true(excel, row) ans_false = self.__get_ans_false(excel, row) qtype = self.__get_qtype(ans_true, ans_false) self.qs[qid] = factory_quest.build(qtype, qid, row, priority, topic, question, ans_true, ans_false, self.logger) self.priorities.add(priority) row += 1 excel.close()
def to_excel(self, xlsx): """ ======================================================================== Description: Output the Table-Statistics into Excel-File. ======================================================================== Arguments: ------------------------------------------------------------------------ 1. xlsx : str (Path to Output Excel-File). ======================================================================== """ excel = Excel(self.template) values = [ self.tname, self.cols_all, self.rows_all, self.rows_duplicate ] row_start = self.row_name col = self.col_val excel.set_values_col(row_start, col, values) for col in self.cols: col.to_excel(excel) excel.save_as(xlsx) excel.close()
def clear_column(xlsx, col, row_start=1): """ ============================================================================ Description: Clear Column Values in Excel File. ============================================================================ Arguments: ---------------------------------------------------------------------------- 1. xlsx : str (Path to Excel-File). 2. col : int (Index of Column to Clear). 3. row_start : int (Row to Start Clear from). ============================================================================ """ assert type(xlsx) == str assert type(col) == int excel = Excel(xlsx) row_last = excel.ws.max_row excel.clear_cells(row=row_start, col=col, row_last=row_last) excel.close()
def to_excel(table, xlsx): excel = Excel(xlsx)
def auto_fill(): """ ============================================================================ Description: AutoFill Excel-Questions Columns (Id, Valid, Priority, Date). ============================================================================ """ row_first = 2 col_id = 1 col_valid = 2 col_priority = 3 col_question = 4 col_date = 7 date = u_datetime.to_str(datetime.now(), 'yymmdd') id_last = params.get('id last') filepaths = u_excel.get_filepaths_questions() for xlsx in filepaths: changed = False excel = Excel(xlsx) row_last = excel.ws.max_row for row in range(row_first, row_last + 1): if excel.is_blank(row, col_question): continue # AutoFill Id if excel.is_blank(row, col_id): excel.set_value(row, col_id, id_last + 1) id_last += 1 changed = True # AutoFill Valid if excel.is_blank(row, col_valid): excel.set_value(row, col_valid, 1) changed = True # AutoFill Priority if excel.is_blank(row, col_priority): excel.set_value(row, col_priority, 'A') changed = True # AutoFill Date if excel.is_blank(row, col_date): excel.set_value(row, col_date, date) changed = True excel.close() if changed: print(xlsx) params.set('id last', id_last)