def save_as_pdf(self, output_pdf=None): if output_pdf: self.xlBook.ExportAsFixedFormat(0, output_pdf, 1, 1, 1, 1, 6) # 指定1-6页打印 logger.info('Save template as PDF file %s success.' % output_pdf) else: logger.error('Save template as PDF file %s success.' % output_pdf)
def set_table_para(self, parameter, values): for index in range(len(values)): self.xlBook.Names(parameter).RefersToRange(index + 1).Value = values[index] print("set %s done.", parameter) logger.info('Set template parameter: %s as value: %s' % (parameter, values))
def save(self, new_filename=None): if new_filename: self.filename = new_filename self.xlBook.SaveAs(new_filename) logger.info('Save template as new file %s success.' % new_filename) else: logger.error('There have no new template file name : %s.' % new_filename)
def __init__(self, filename=None): self.xlApp = win32com.client.Dispatch('Excel.Application') self.xlApp.Visible = 0 self.xlApp.DisplayAlerts = 0 if filename: self.filename = filename self.xlBook = self.xlApp.Workbooks.Open(filename) logger.info('Open %s success.' % filename) else: logger.error('There was no file:%s' % filename)
def check_kill_process(process_name): try: wmi = win32com.client.GetObject('winmgmts:') process_code_cov = wmi.ExecQuery( 'select * from Win32_Process where Name="%s"' % process_name) if len(process_code_cov) > 0: os.system('taskkill /IM ' + process_name + ' /F') logger.info("kill %s process success. " % process_name) else: logger.info("%s process is not exist. " % process_name) except Exception as e: logger.error("check %s process fail: %s" % (process_name, e))
# -*- coding: utf-8 -*- from utils.mylogger import logger if __name__ == "__main__": logger.info('******************Start generate MR Healthy Month Report************.') logger.info('******************Stop generate MR Healthy Month Report*************.')
class TestMyLogger(unittest.TestCase): logger.debug('this is a logger debug message') logger.info('this is a logger info message') logger.warning('this is a logger warning message') logger.error('this is a logger error message') logger.critical('this is a logger critical message')
def set_para(self, parameter, value): self.xlBook.Names(parameter).RefersToRange.Value = value logger.info('Set template parameter: %s as value: %s' % (parameter, value))
def close(self): self.xlBook.Close(SaveChanges=0) self.xlApp.Application.Quit() del self.xlApp logger.info('Close template excel success.')