def get_report_info_perid( self, cmd, diff_time, thre_time, max_number, ): # 发送要执行的命令 pre_time_stamp = [0] * 4 self._channel.send(cmd + '\r') # 回显很长的命令可能执行较久,通过循环分批次取回回显 index = [0] * 4 line_counter = 0 line_feed_byte = '\n'.encode(self.encoding) while True: buffer = self._channel.recv(65535) if len(buffer) == 0: logger.info('end______________') break lines = buffer.split(line_feed_byte) for current_line in lines: style = None line = current_line.decode(self.encoding) # logger.debug('shell显示:%s' % line) col = self.check_type(line) if not line.startswith(self.rq) or col == 10: line_counter += 1 continue time_stamp = int( time.mktime( time.strptime(' '.join([line[:8], line[9:17]]), "%Y%m%d %H:%M:%S"))) time_stamp_dec = line[18:21] # 精确到毫秒 time_stamp = time_stamp * 1000 + int(time_stamp_dec) logger.info('%s:%s' % (senior_name[col], time_stamp)) if pre_time_stamp[col] == 0: pre_time_stamp[col] = time_stamp else: if abs((time_stamp - pre_time_stamp[col]) - diff_time[col]) > thre_time[col]: logger.error('两帧数据间隔为{}ms,时间戳分别为:({},{}),行号:{}'.format( time_stamp - pre_time_stamp[col], time_stamp, pre_time_stamp[col], index[col])) style = XFStyle() fnt = Font() fnt.name = u'微软雅黑' # 设置其字体为微软雅黑 fnt.colour_index = 2 # 设置其字体颜色 fnt.bold = True style.font = fnt self.write_xl(index[col] + 1, col * 2, time_stamp) self.write_xl(index[col] + 1, col * 2 + 1, time_stamp - pre_time_stamp[col], style=style) index[col] += 1 pre_time_stamp[col] = time_stamp line_counter += 1
def output(file_or_stream, sheetname, headers, values, encoding = 'utf8', footer_text = None, footer_link = None): import xlwt book = xlwt.Workbook(encoding) sh = book.add_sheet(sheetname) datestyle = XFStyle() datestyle.num_format_str = 'DD/MM/YYYY' timestyle = XFStyle() timestyle.num_format_str = 'HH:MM:SS' header_font = Font() header_font.bold = True al = Alignment() al.horz = Alignment.HORZ_CENTER header_style = XFStyle() header_style.font = header_font header_style.alignment = al for i,header in enumerate(headers): sh.write(0, i, header, header_style) sh.set_panes_frozen(True) # frozen headings instead of split panes sh.set_horz_split_pos(1) # in general, freeze after last heading row sh.set_remove_splits(True) # if user does unfreeze, don't leave a split there for j, row in enumerate(values): for i, value in enumerate(row): if value.__class__ == date: sh.write(j+1, i, value, datestyle) elif value.__class__ == time: sh.write(j+1, i, value, timestyle) else: sh.write(j+1, i, value) if footer_link and footer_text: link_font = Font() link_font.name = 'Verdana' link_font.colour_index = 4 link_font.height = 20*8 al = Alignment() al.horz = Alignment.HORZ_CENTER al.vert = Alignment.VERT_BOTTOM link_style = XFStyle() link_style.font = link_font link_style.alignment = al row = len(values) + 1 sh.write_merge(row, row, 0, len(headers)-1, Formula('HYPERLINK("' + footer_link + '";"' + footer_text + '")'), link_style) book.save(file_or_stream)
def _getStyle(self, org_style, org_font): from xlwt import XFStyle, Font, Borders, Pattern # font font = Font() font.name = org_font.name font.height = org_font.height font.italic = org_font.italic font.struck_out = org_font.struck_out font.outline = org_font.outline font.shadow = org_font.shadow font.colour_index = org_font.colour_index font.bold = org_font.bold font._weight = org_font.weight font.escapement = org_font.escapement_type font.underline = org_font.underline_type font.family = org_font.family font.charset = org_font.character_set # border borders = Borders() borders.left = Borders.THIN #org_style.xf.border.left_line_style borders.right = Borders.THIN #org_style.xf.border.right_line_style borders.top = Borders.THIN #org_style.xf.border.top_line_style borders.bottom = Borders.THIN #org_style.xf.border.bottom_line_style #borders.diag = self.NO_LINE borders.left_colour = org_style.xf.border.left_colour_index borders.right_colour = org_style.xf.border.right_colour_index borders.top_colour = org_style.xf.border.top_colour_index borders.bottom_colour = org_style.xf.border.bottom_colour_index #borders.diag_colour = org_style.xf.border.left_colour_index #borders.need_diag1 = self.NO_NEED_DIAG1 #borders.need_diag2 = self.NO_NEED_DIAG2 # Pattern pattern = Pattern() pattern.pattern = org_style.xf.background.fill_pattern pattern.pattern_fore_colour = org_style.xf.background.pattern_colour_index pattern.pattern_back_colour = org_style.xf.background.background_colour_index # style = XFStyle() style.borders = borders style.font = font style.pattern = pattern return style
def get_sheet_title_style(bg_color=0x39, font_color=0x0, font_size=300, has_pattern=True, horz_center=True): fnt = Font() fnt.name = 'Arial' fnt.colour_index = font_color fnt.bold = True fnt.height = font_size borders = Borders() borders.left = 1 borders.right = 1 borders.top = 1 borders.bottom = 1 al = Alignment() if horz_center: al.horz = Alignment.HORZ_CENTER else: al.horz = Alignment.HORZ_LEFT al.vert = Alignment.VERT_CENTER pattern = None if has_pattern: pattern = Pattern() pattern.pattern = 1 pattern.pattern_fore_colour = bg_color pattern.pattern_back_colour = bg_color style = XFStyle() style.font = fnt style.borders = borders style.alignment = al if pattern: style.pattern = pattern return style
def create_template(self): try: open_workbook(self.template_path) except FileNotFoundError: # 文件夹下无模板文件,直接创建然后导入数据 wb = Workbook(encoding='ascii') ws = wb.add_sheet("1") style1 = XFStyle() font1 = Font() font1.bold = True style1.font = font1 ws.write(0, 0, OLD_FILE_NAME, style1) ws.write(0, 1, NEW_FILE_NAME, style1) style2 = XFStyle() font2 = Font() font2.bold = True font2.colour_index = 2 style2.font = font2 ws.write(1, 3, TEMPLATE_HINT, style2) new_row_id = 1 for i in range(len(self.table_name_list0)): if i not in self.disable_pos_list: ws.write(new_row_id, 0, self.table_name_list0[i]) new_row_id += 1 wb.save(self.template_path) return # 文件夹下已经存在模板文件 # 暂时不检查完整性 rb = open_workbook(self.template_path, formatting_info=True) r_sheet = rb.sheet_by_index(0) wb = copy(rb) sheet = wb.get_sheet(0) def update_old_name(old_name_list, disable_pos_list): needed_add_name_list = [] old_name_index = 0 # 旧文件名列序号 name0_list = r_sheet.col_values(old_name_index, start_rowx=1, end_rowx=None) for i in range(len(old_name_list)): if i not in disable_pos_list: if old_name_list[i] not in name0_list: needed_add_name_list.append(old_name_list[i]) if len(needed_add_name_list) == 0: print("没有文件名需要添加到模板文件中,或者所有文件名已经添加") return n_row = r_sheet.nrows print("原模板文件中已经有" + str(n_row) + "行") for name in needed_add_name_list: print("将文件名" + name + "添加到模板文件中") sheet.write(n_row, old_name_index, name) n_row += 1 update_old_name(self.table_name_list0, self.disable_pos_list) try: wb.save(self.template_path) except PermissionError: messagebox.showwarning("模板文件异常", "请关闭文件夹下的模板文件后再重新导入") return messagebox.showinfo("一切正常", "文件导入成功,模板文件已生成。\n请打开对应文件夹的模板文件编辑新文件名")
def exportToExcel(self,objectProject): book = Workbook(); sheet1 = book.add_sheet('Sheet 1') sheet1.col(1).width = 256*20; sheet1.col(2).width = 256*80; sheet1.col(3).width = 256*10; sheet1.col(4).width = 256*20; default_book_style = book.default_style default_book_style.font.height = 20 * 36 # 36pt fnt = Font() fnt.name = 'Arial' fnt.colour_index = 4 fnt.bold = True borders = Borders() borders.left = Borders.THIN borders.right = Borders.THIN borders.top = Borders.THIN borders.bottom = Borders.THIN pattern = Pattern(); pattern.pattern = Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 23 algn1 = Alignment(); algn1.wrap = 1; #algn1.horz = Alignment.HORZ_CENTER #algn1.vert = Alignment.VERT_TOP alignHeader = Alignment(); alignHeader.horz = Alignment.HORZ_CENTER; alignTop = Alignment(); alignTop.vert = Alignment.VERT_TOP print "export"; if( objectProject): i=0; print "start" ; styleHead = XFStyle(); styleHead.font = fnt; styleHead.borders = borders; styleHead.pattern = pattern; styleHead.alignment = alignHeader; row1 = sheet1.row(i) ; row1.write(0, ('risk id').decode('UTF8'),styleHead ); sheet1.write_merge(i, i, 1, 2, ('รายละเอียด').decode('UTF8') ,styleHead ); # row1.write(1, ('รายละเอียด').decode('UTF8')); row1.write(3, ('วันที่รายงาน').decode('UTF8'), styleHead ); row1.write(4, ('หน่วยที่รายงาน').decode('UTF8'), styleHead ); i=i+1; style1 = XFStyle(); style1.alignment = algn1; #style0 = xlwt.easyxf('font: name Times New Roman size 20, color-index black, bold on') for value in objectProject: row1 = sheet1.row(i) ; styleRowDetail = XFStyle(); styleRowDetail.borders = borders; styleRowDetail.alignment = alignTop; StyleRowDetailWrap = styleRowDetail ; StyleRowDetailWrap.alignment = algn1; styleDate = XFStyle() styleDate.num_format_str = 'DD-MM-YYYY' ; #'D-MMM-YY'; styleDate.borders = borders; row1.write(0, value.get('risk_management_id'),styleRowDetail ); #row1.write(1, value.get('risk_detail').decode('UTF8') , style1); sheet1.write_merge(i, i, 1, 2, value.get('risk_detail').decode('UTF8') , StyleRowDetailWrap ); row1.write(3, value.get('report_date') ,styleDate); row1.write(4, value.get('report').decode('UTF8') ,styleRowDetail ); i=i+1; row1 = sheet1.row(i) ; row1.write(0," " ); row1.write(1,('หน่วยที่เกี่ยวข้อง').decode('UTF8') ,styleHead ); sheet1.write_merge(i, i, 2, 3,('รายละเอียดการตอบ').decode('UTF8') , styleHead ); i=i+1; for sub in value.get('response') : row1 = sheet1.row(i) ; row1.write(0," " ); row1.write(1,sub.get('risk_team').decode('UTF8') , styleRowDetail ); sheet1.write_merge(i, i, 2, 3,sub.get('result').decode('UTF8') , StyleRowDetailWrap ); i=i+1; dirTempFile = gettempdir() + _os.sep + str('simple.xls'); print dirTempFile; book.save(dirTempFile);
def exportReport5ToExcel(self,objectProject): book = Workbook(); sheet1 = book.add_sheet('Sheet 1'); sheet1.col(1).width = 256*80; sheet1.col(2).width = 256*10; sheet1.col(3).width = 256*20; borders = Borders() borders.left = Borders.THIN borders.right = Borders.THIN borders.top = Borders.THIN borders.bottom = Borders.THIN pattern = Pattern(); pattern.pattern = Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 23 wrap = Alignment(); wrap.wrap = 1; wrap.vert = Alignment.VERT_TOP alignHeader = Alignment(); alignHeader.horz = Alignment.HORZ_CENTER; alignTop = Alignment(); alignTop.vert = Alignment.VERT_TOP fnt = Font() fnt.name = 'Arial' fnt.colour_index = 4 fnt.bold = True styleWrap = XFStyle(); styleWrap.alignment = wrap; styleHead = XFStyle(); styleHead.font = fnt; styleHead.borders = borders; styleHead.pattern = pattern; styleHead.alignment = alignHeader; styleRowDetail = XFStyle(); styleRowDetail.borders = borders; styleRowDetail.alignment = alignTop; styleDate = XFStyle() styleDate.num_format_str = 'DD-MM-YYYY' ; #'D-MMM-YY'; styleDate.borders = borders; styleDate.alignment = alignTop; StyleRowDetailWrap = styleRowDetail ; StyleRowDetailWrap.alignment = wrap; if( objectProject): i=0; row1 = sheet1.row(i) ; row1.write(0, ('risk id').decode('UTF8'),styleHead ); #sheet1.write_merge(i, i, 1, 2, ('รายละเอียด').decode('UTF8') ); row1.write(1, ('รายละเอียด').decode('UTF8'),styleHead); row1.write(2, ('วันที่รายงาน').decode('UTF8'),styleHead ); row1.write(3, ('หน่วยที่รายงาน').decode('UTF8') ,styleHead); i=i+1; for value in objectProject: row1 = sheet1.row(i) ; row1.write(0, value.get('risk_management_id') ,styleRowDetail ); row1.write(1, value.get('risk_detail').decode('UTF8'),StyleRowDetailWrap ); #sheet1.write_merge(i, i, 1, 2, value.get('risk_detail').decode('UTF8') , StyleRowDetailWrap ); row1.write(2, value.get('report_date') ,styleDate ); row1.write(3, value.get('report').decode('UTF8') ,styleRowDetail ); i=i+1; for sub in value.get('response') : row1 = sheet1.row(i) ; row1.write(0," " ); text = "(" + sub.get('risk_team').decode('UTF8') + " ) " + sub.get('result').decode('UTF8'); row1.write(1, text ,StyleRowDetailWrap ); i=i+1; dirTempFile = gettempdir() + _os.sep + str('simpleReport5.xls'); book.save(dirTempFile); return dirTempFile;
def exportReport1ToExcel(self,objectProject): book = Workbook(); sheet1 = book.add_sheet('Sheet 1'); sheet1.col(1).width = 256*20; sheet1.col(2).width = 256*80; sheet1.col(3).width = 256*10; sheet1.col(4).width = 256*10; sheet1.col(5).width = 256*20; sheet1.col(6).width = 256*20; borders = Borders() borders.left = Borders.THIN borders.right = Borders.THIN borders.top = Borders.THIN borders.bottom = Borders.THIN pattern = Pattern(); pattern.pattern = Pattern.SOLID_PATTERN pattern.pattern_fore_colour = 23 wrap = Alignment(); wrap.wrap = 1; wrap.vert = Alignment.VERT_TOP alignHeader = Alignment(); alignHeader.horz = Alignment.HORZ_CENTER; alignTop = Alignment(); alignTop.vert = Alignment.VERT_TOP fnt = Font() fnt.name = 'Arial' fnt.colour_index = 4 fnt.bold = True styleWrap = XFStyle(); styleWrap.alignment = wrap; styleHead = XFStyle(); styleHead.font = fnt; styleHead.borders = borders; styleHead.pattern = pattern; styleHead.alignment = alignHeader; styleRowDetail = XFStyle(); styleRowDetail.borders = borders; styleRowDetail.alignment = alignTop; styleDate = XFStyle() styleDate.num_format_str = 'DD-MM-YYYY' ; #'D-MMM-YY'; styleDate.borders = borders; styleDate.alignment = alignTop; StyleRowDetailWrap = styleRowDetail ; StyleRowDetailWrap.alignment = wrap; if( objectProject): i=0; row1 = sheet1.row(i) ; row1.write(0, ('ลำดับที่').decode('UTF8') ,styleHead); #sheet1.write_merge(i, i, 1, 2, ('รายละเอียด').decode('UTF8') ); row1.write(1, ('เลขความเสี่ยง').decode('UTF8'),styleHead ); row1.write(2, ('อุบัติการณ์/ภาวะไม่พึงประสงค์').decode('UTF8'),styleHead); row1.write(3, ('วันที่รายงาน').decode('UTF8'),styleHead ); row1.write(4, ('ความรุนแรง').decode('UTF8'),styleHead ); row1.write(5, ('ด้าน/โปรแกรม').decode('UTF8') ,styleHead); row1.write(6, ('หน่วยที่รายงาน').decode('UTF8') ,styleHead); i=i+1; for value in objectProject: row1 = sheet1.row(i) ; row1.write(0, value.get('row') ,styleRowDetail ); row1.write(1, str(value.get('risk_id')).decode('UTF8'),styleRowDetail ); row1.write(2, value.get('detail').decode('UTF8'),StyleRowDetailWrap ); row1.write(3, value.get('report_date') ,styleDate ); row1.write(4, value.get('level').decode('UTF8') ,styleRowDetail ); row1.write(5, value.get('pro').decode('UTF8') ,styleRowDetail ); row1.write(6, value.get('reporter').decode('UTF8') ,styleRowDetail ); i=i+1; row2 = sheet1.row(i) ; row2.write(2, ('รายละเอียด').decode('UTF8'),styleHead); row2.write(3, ('หน่วยที่ตอบ').decode('UTF8'),styleHead ); row2.write(4, ('ระยะเวลาตอบ').decode('UTF8'),styleHead ); i=i+1; for resp in value.get('responsible'): row2 = sheet1.row(i) ; row2.write(2, str(resp.get('detail')).decode('UTF8'),StyleRowDetailWrap); row2.write(3, str(resp.get('service_name')).decode('UTF8'),styleRowDetail ); row2.write(4, str(resp.get('report_date')).decode('UTF8'),styleRowDetail ); i=i+1; dirTempFile = gettempdir() + _os.sep + str('simpleReport1.xls'); book.save(dirTempFile); return dirTempFile;
def button_print_sale_report(self): filename = 'Sale Wizard Report.xls' string = 'sale Report.xls' wb = xlwt.Workbook(encoding='utf-8') worksheet = wb.add_sheet(string) style = XFStyle() fnt = Font() fnt.colour_index = 0x36 fnt.bold = True fnt.width = 256 * 30 style.font = fnt style1 = XFStyle() fnt = Font() fnt.colour_index = 0x8 fnt.bold = True fnt.width = 256 * 30 style1.font = fnt worksheet.write_merge( 0, 1, 2, 3, "Transport Sale Report", xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz center;' )) worksheet.write( 2, 0, 'Sale Order No', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) worksheet.write( 2, 1, 'Customer', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) worksheet.write( 2, 2, 'Confirmation Date', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) worksheet.write( 2, 3, 'Product', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) worksheet.write( 2, 4, 'Order Quantity', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) worksheet.write( 2, 5, 'Unit', xlwt.easyxf( 'font: height 200, name Arial, colour_index black, bold on, italic off; align: wrap on, vert centre, horiz left;' )) a = 3 # sale_order_ids = self.env['sale.order'].search([]) sale_order = self.sale_order_ids print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", sale_order) if sale_order: for sale_id in sale_order: # worksheet.write(a, 0, sale_id.name) # worksheet.write(a, 1, sale_id.partner_id.name) # worksheet.write(a, 2, sale_id.confirmation_date) for line in sale_id.order_line: worksheet.write(a, 0, sale_id.name) worksheet.write(a, 1, sale_id.partner_id.name) worksheet.write(a, 2, sale_id.confirmation_date) worksheet.write(a, 3, line.product_id.name) worksheet.write(a, 4, line.product_uom_qty) worksheet.write(a, 5, line.price_unit) a += 1 else: sale_order_ids = self.env['sale.order'].search([]) for id in sale_order_ids: if id.state == "done": # print(id) for sale_id in id: for line in sale_id.order_line: worksheet.write(a, 0, sale_id.name) worksheet.write(a, 1, sale_id.partner_id.name) worksheet.write(a, 2, sale_id.confirmation_date) worksheet.write(a, 3, line.product_id.name) worksheet.write(a, 4, line.product_uom_qty) worksheet.write(a, 5, line.price_unit) a += 1 fp = BytesIO() wb.save(fp) out = base64.encodestring(fp.getvalue()) view_report_id = self.env['view.report.sale.wizard'].create({ 'file_name': out, 'datas_fname': filename }) return { 'res_id': view_report_id.id, 'name': '', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'view.report.sale.wizard', 'view_id': False, 'type': 'ir.actions.act_window', }
def salvar(trelica_objeto): borders = Borders() bord = 2 borders.left = bord borders.right = bord borders.top = bord borders.bottom = bord bord_lateral = Borders() bord = 2 bord_lateral.left = bord bord_lateral.right = bord ## FONTES fonte_titulo = Font() fonte_titulo.name = 'Times New Roman' fonte_titulo.bold = True fonte_titulo.height = 240 fonte_titulo.borders = bord_lateral fonte_normal = Font() fonte_normal.name = 'Times New Roman' fonte_normal.borders = bord_lateral fonte_normal_problema = Font() fonte_normal_problema.name = 'Times New Roman' fonte_normal_problema.borders = bord_lateral fonte_normal_problema.colour_index = 2 #5=amarelo | 4=azul | 3=verde | 2=vermelho fonte_destaque = Font() fonte_destaque.name = 'Arial' fonte_destaque.colour_index = 4 # azul ## ESTILOS estilo_titulo = XFStyle() estilo_titulo.borders = borders estilo_titulo.font = fonte_titulo estilo_titulo.alignment.horz = 2 estilo_sub_titulo = XFStyle() estilo_sub_titulo.borders = borders estilo_sub_titulo.alignment.horz = 2 estilo_sub_titulo.font = fonte_destaque estilo_normal = XFStyle() estilo_normal.font = fonte_normal estilo_normal.num_format_str = "#,##0.00" estilo_normal.alignment.horz = 2 estilo_normal_esquerda = XFStyle() estilo_normal_esquerda.font = fonte_normal estilo_normal_tabela = XFStyle() estilo_normal_tabela.font = fonte_normal estilo_normal_tabela.borders = borders estilo_normal_tabela.alignment.horz = 2 estilo_normal_tabela.num_format_str = "#,##0.00" estilo_normal_tabela_red = XFStyle() estilo_normal_tabela_red.font = fonte_normal_problema estilo_normal_tabela_red.borders = borders estilo_normal_tabela_red.alignment.horz = 2 estilo_normal_tabela_red.num_format_str = "#,##0.00" estilo_destaque = XFStyle() estilo_destaque.font = fonte_destaque # estilo_destaque.alignment.horz = 2 estilo_destaque.alignment.vertical = 2 estilo_destaque_tabela = XFStyle() estilo_destaque_tabela.font = fonte_destaque estilo_destaque_tabela.borders = borders estilo_destaque_tabela.alignment.horz = 2 estilo_id_tabela = estilo_normal_tabela estilo_id_tabela.alignment.num_format_str = "#0" text_file = filedialog.asksaveasfile(mode='w', defaultextension=".xls", filetypes=[('excel files', '.xls')]) wb = Workbook() sheet = wb.add_sheet('Treliceca') sheet.col(2).width = 0x0d00 + 22 sheet.col(4).width = 0x0d00 + 40 sheet.col(7).width = 0x0d00 + 15 sheet.col(8).width = 0x0d00 + 15 vt = trelica_objeto.vt banzo_reto = trelica_objeto.banzo_reto # padrão de viga treliçada viga = 'Viga de Cobertura Treliçada com banzos paralelos' if vt == 1: viga = 'Viga de Transição Treliçada' if banzo_reto == 1: viga = 'Viga de Cobertura Treliçada com banzo inferior reto' # combinações de carregamentos atuando na treliça carregamento_grav = trelica_objeto.carregamentos[0] carregamento_cv = trelica_objeto.carregamentos[1] vaos = '' for ponto in trelica_objeto.pontos_vao: vaos += ' ' + str(ponto[0]) + ',' # pesos calculados da treliça peso = trelica_objeto.peso peso_dobrado = trelica_objeto.peso_dobrado peso_soldado = trelica_objeto.peso_soldado peso_linear = trelica_objeto.peso_linear peso_miscelanias = trelica_objeto.peso_miscelanias # pecas = trelica_objeto.pecas h_viga = trelica_objeto.h_viga # lista com as barras da treliça, separadas por tipo banzos_inferiores = [] banzos_superiores = [] diagonais = [] montantes = [] for barra in trelica_objeto.barras_objetos: if barra.tipo == 'diagonal': diagonais.append(barra) elif barra.tipo == 'montante': montantes.append(barra) elif barra.tipo == 'banzo-superior': banzos_superiores.append(barra) elif barra.tipo == 'banzo-inferior': banzos_inferiores.append(barra) lista_barras = [banzos_inferiores, banzos_superiores, montantes, diagonais] linha = 0 # inserindo o titulo = viga sheet.write_merge(linha, linha, 1, 11, viga, estilo_titulo) linha += 1 sheet.write_merge(linha, linha, 1, 11, 'Dados da Viga Treliçada', estilo_sub_titulo) linha += 1 sheet.write_merge(linha, linha, 8, 11, 'Combinações [kg/m]', estilo_destaque_tabela) sheet.write(linha, 1, 'Vãos[m]=', estilo_destaque) sheet.write_merge(linha, linha, 2, 4, vaos, estilo_normal) linha += 1 sheet.write(linha, 1, 'Altura [m]', estilo_destaque) sheet.write(linha, 2, h_viga, estilo_normal) sheet.write(linha, 4, 'Soldado [kg]', estilo_destaque) sheet.write(linha, 5, peso_soldado, estilo_normal) sheet.write_merge(linha, linha, 8, 9, 'Grav. ', estilo_destaque_tabela) sheet.write_merge(linha, linha, 10, 11, 'Vento', estilo_destaque_tabela) linha += 1 sheet.write(linha, 1, 'Peso [kg]', estilo_destaque) sheet.write(linha, 2, peso, estilo_normal) sheet.write(linha, 4, 'Dobrado [kg]', estilo_destaque) sheet.write(linha, 5, peso_dobrado, estilo_normal) sheet.write_merge(linha, linha, 8, 9, '1.25xCP + 1.5xSC + 1.4xSU', estilo_normal_tabela) sheet.write_merge(linha, linha, 10, 11, '1.0xCP + 1.4xCV', estilo_normal_tabela) linha += 1 sheet.write(linha, 1, 'Y [kg/m]', estilo_destaque) sheet.write(linha, 2, peso_linear, estilo_normal) sheet.write(linha, 4, 'Miscelanias [kg]', estilo_destaque) sheet.write(linha, 5, peso_miscelanias, estilo_normal) sheet.write_merge(linha, linha, 8, 9, carregamento_grav, estilo_normal_tabela) sheet.write_merge(linha, linha, 10, 11, carregamento_cv, estilo_normal_tabela) linha += 2 # Barras da treliça sheet.write_merge(linha, linha, 1, 11, 'Barras da Treliça', estilo_destaque_tabela) linha += 1 sheet.write(linha, 1, 'id', estilo_destaque_tabela) sheet.write(linha, 2, ' ', estilo_destaque_tabela) sheet.write(linha, 3, 'tipo ', estilo_destaque_tabela) sheet.write(linha, 4, 'seção ', estilo_destaque_tabela) sheet.write(linha, 5, 'Peso [kg]', estilo_destaque_tabela) sheet.write(linha, 6, 'l [m]', estilo_destaque_tabela) sheet.write(linha, 7, 'Comp [kgf]', estilo_destaque_tabela) sheet.write(linha, 8, 'Tração [kgf]', estilo_destaque_tabela) sheet.write(linha, 9, 'Ratio ', estilo_destaque_tabela) sheet.write(linha, 10, 'compr.', estilo_destaque_tabela) sheet.write(linha, 11, 'tração', estilo_destaque_tabela) linha += 1 for lista in lista_barras: for barra in lista: estilo = estilo_normal_tabela if barra.ratio > 1: estilo = estilo_normal_tabela_red else: estilo = estilo_normal_tabela sheet.write(linha, 1, barra.id, estilo) sheet.write(linha, 2, barra.tipo, estilo) sheet.write(linha, 3, barra.section.tipo, estilo) sheet.write(linha, 4, stringSecaoBarra(barra), estilo) sheet.write(linha, 5, barra.peso, estilo) sheet.write(linha, 6, barra.comprimento(), estilo) sheet.write(linha, 7, barra.compressao, estilo) sheet.write(linha, 8, barra.tracao, estilo) sheet.write(linha, 9, barra.ratio, estilo) sheet.write(linha, 10, barra.ratio_compressao, estilo) sheet.write(linha, 11, barra.ratio_tracao, estilo) linha += 1 linha = 1 sheet.write(linha, 15, 'Reações nos Apoios = [h1, v1, v2, v3, ..., vn] ', estilo_normal_esquerda) linha += 1 sheet.write(linha, 15, 'Apoios numerados conforme desenho do canvas', estilo_normal_esquerda) linha += 1 sheet.write(linha, 15, 'Numeração da esquerda, para direita', estilo_normal_esquerda) linha += 1 sheet.write(linha, 15, 'F', estilo_destaque_tabela) sheet.write_merge(linha, linha, 16, 17, 'kgf', estilo_destaque_tabela) linha += 1 sheet.write(linha, 15, ' ', estilo_destaque_tabela) sheet.write(linha, 16, 'grav', estilo_destaque_tabela) sheet.write(linha, 17, 'vento', estilo_destaque_tabela) linha += 1 reacoes_grav = trelica_objeto.reacoes_grav reacoes_cv = trelica_objeto.reacoes_cv qtd_reacoes = len(reacoes_grav) sheet.write(linha, 15, 'Fx 1', estilo_destaque_tabela) sheet.write(linha, 16, reacoes_grav[0], estilo_normal_tabela) sheet.write(linha, 17, reacoes_cv[0], estilo_normal_tabela) linha += 1 for i in range(1, qtd_reacoes): sheet.write(linha, 15, 'Fy {:.0f}'.format(i), estilo_destaque_tabela) sheet.write(linha, 16, reacoes_grav[i], estilo_normal_tabela) sheet.write(linha, 17, reacoes_cv[i], estilo_normal_tabela) linha += 1 wb.save(text_file.name)
elif seed.isdigit(): seed = int(seed) random.seed(seed) ok = True else: print('Неверный ввод! Введите произвольное число или нажмите Enter, чтобы пропустить') document = Document() rb = open_workbook('data\\answers.xlsx') sheet = rb.sheet_by_index(0) font0 = Font() font0.name = 'Times New Roman' font0.colour_index = 2 font0.bold = True wb = Workbook() ws = wb.add_sheet('Лист1') l = random.sample(l, ll) f = open('data\\questions.txt', 'r').read() for n, q in enumerate(l): add_question(f, q, n+1, images, document, sheet, ws) document.save('questions.docx') wb.save('new_answers.xls') print('Файл с вопросами: questions.docx') print('Файл с ответами: new_answers.xls')