python3 xlwt 配置文件读写Agent

import os
import xlwt

class configAgent:
    sequence = 0
    targetFile = ''
    defautPolicy = None
    worksheet = None
    
    def __init__(self, targetFile):
        self.targetFile = targetFile
        self.defautPolicy = xlwt.Workbook(encoding = 'ascii')
        self.worksheet = self.defautPolicy.add_sheet('defaultStrategy')
    
    def write_title(self, titles):
        i = 0
        for title in titles:
            self.worksheet.write(0,i, label = title)
            i = i + 1
    
    def write_row(self, words):
        i = 1
        for word in words:
            self.worksheet.write(self.sequence, i, label = str(i * self.sequence))
            i = i + 1
        self.sequence = self.sequence + 1
        
    def write_to_file(self):
        self.defautPolicy.save(self.targetFile)
        
        
        
testAgentFile = r"K:\python\xlrdwtutils\test.xls"
myAgent = configAgent(testAgentFile)
myAgent.write_row(('hello', 'world'))
myAgent.write_to_file()
os.system("pause")

猜你喜欢

转载自www.cnblogs.com/secoolar/p/9256069.html