xlsxwriter - Python script to write and append a single xls document by every functions inside the script. Currently its overwriting the sheet -
python script write , append single xls document every functions inside script. overwriting sheet.
here's code:
import os import os.path import mysqldb import configuration import hashlib import xlsxwriter lxml import etree def check(): try: path='config.txt' workbook = xlsxwriter.workbook('demo.xlsx') worksheet = workbook.add_worksheet() worksheet.set_column('a:a', 20) bold = workbook.add_format({'bold': true}) worksheet.write('a1', 'file name',bold) worksheet.write('b1', 'is present', bold) worksheet.write(2, 1, 'yes') worksheet.write('d1', 'verification', bold) worksheet.write(2, 0, 'config.txt') if os.path.isfile(path) , os.access(path, os.r_ok): print "config.txt file exists , readable" global cur1 var = configuration.client['client_id'] host = configuration.mysql_host['host'] username = configuration.mysql_username['username'] password = configuration.mysql_password['password'] connection=mysqldb.connect( user=username, passwd=password, db="db") cur1=connection.cursor() cur1.execute("select md5sum **** file_name = 'config.txt' , sd = '%s'" % var) row=cur1.fetchone() ele = 'ncconfig.txt' md5 in row: file_name = 'config.txt' open(file_name) file_to_check: data = file_to_check.read() md5_returned = hashlib.md5(data).hexdigest() if md5 == md5_returned: print('file %s md5 has been verified' % ele) worksheet.write(2, 3, 'verified') workbook.close() else: print('file %s md5 not matching....so syncing failed ' % ele) worksheet.write(2, 3, 'failed') workbook.close() cur1.close() connection.close() else: print "either config.txt file missing or not readable" worksheet.write(2, 3, 'failed') worksheet.write('g1','reason', bold) worksheet.write(2,5,'may file not present') workbook.close() except mysqldb.error, e: print "error %d: %s" % (e.args[0], e.args[1]) def check_md5_for_rconfig(): try: path='rconfig.txt' if os.path.isfile(path) , os.access(path, os.r_ok): print "rconfig.txt file exists , readable" global cur1 var = configuration.client['client_id'] host = configuration.mysql_host['host'] username = configuration.mysql_username['username'] password = configuration.mysql_password['password'] connection=mysqldb.connect( user=username, passwd=password, db="db") cur1=connection.cursor() cur1.execute("select md5sum **** file_name = 'rconfig.txt' , sd = '%s'" % var) row=cur1.fetchone() ele = 'rconfig.txt' md5 in row: file_name = 'rconfig.txt' open(file_name) file_to_check: data = file_to_check.read() md5_returned = hashlib.md5(data).hexdigest() if md5 == md5_returned: print('file %s md5 has been verified' % ele) else: print('file %s md5 not matching....so syncing failed ' % ele) cur1.close() connection.close() else: print "either rconfig.txt file missing or not readable" except mysqldb.error, e: print "error %d: %s" % (e.args[0], e.args[1])
update should answer question: overflow answer here! read xlmswriter not modify existing excel files, there's module in link
with open(file_name) file_to_check:
should be
with open(file_name, 'rb' ) file_to_check:
for both read instances
are trying append worksheet? see everytime check() preformed writes same filename before , each worksheet.write inserts data previous defined spots, overwrite existing data in file, haven't worked xlswriter maybe it'll append that's see.
Comments
Post a Comment