def main(logfiles,dir_path): if len(logfiles) != 0: book = Workbook('utf-8') # crate the cover sheet sheet0 = book.add_sheet('Cover', cell_overwrite_ok=True) row0 = sheet0.row(0) row0.write(0, "ID") row0.write(1, "FILE") row0.write(2, "SHEET") tall_style = Style.easyxf('font:height 72;') row0.set_style(tall_style) sheet0.col(1).width = 256 * 50 for item in logfiles: print "processed file:" + os.path.split(item)[1] new_row = sheet0.row(logfiles.index(item) + 1) new_row.write(0, logfiles.index(item) + 1) click = '#sheet%s!A1' % str(logfiles.index(item)) text = os.path.split(item)[1] style = Style.easyxf('font: underline single,color blue;') new_row.write(1, Formula('HYPERLINK("%s";"%s")' % (click, text)), style) new_row.write(2, 'sheet' + str(logfiles.index(item))) # creat other sheet out_putlist = get_formatted_in_a_file(item) Write_To_excel(book, 'sheet' + str(logfiles.index(item)), out_putlist) save_path = os.path.join(dir_path, 'Aresult.xls') book.save(save_path) else: print "the dirtory doesn't contains any log file"
def generateReport(self, students, directory, name): wb = Workbook() report = wb.add_sheet(name) bold = Style.easyxf("font: bold on;") headers = [ "Nombres", "Apellidos", "ROL", "RUT", "Carrera", "Paralelo", "% de Copia", "", "Nombres", "Apellidos", "ROL", "RUT", "Carrera", "Paralelo", "% de Copia", "Lineas Similares", "MOSS File", ] for column, header in enumerate(headers): report.write(0, column, header, bold) row = 1 for results in students.values(): for result in results: for column, value in enumerate(self.mapResultToReport(result)): report.write(row, column, value) row += 1 timestamp = datetime.now().strftime("%Y-%m-%d %H-%M-%S") fileName = name + " " + timestamp + ".xls" filePath = path.join(directory, fileName) wb.save(filePath)
return fileslList except IOError, msg: print msg logfiles = [] logfiles = get_logfile_in_dir( r'c:\arcgisserver\logs\JIANGMB.ESRICHINA.COM\server') book = Workbook('utf-8') #crate the cover sheet sheet0 = book.add_sheet('Cover', cell_overwrite_ok=True) row0 = sheet0.row(0) row0.write(0, "ID") row0.write(1, "FILE") row0.write(2, "SHEET") tall_style = Style.easyxf('font:height 72;') row0.set_style(tall_style) sheet0.col(1).width = 256 * 50 for item in logfiles: new_row = sheet0.row(logfiles.index(item) + 1) new_row.write(0, logfiles.index(item) + 1) click = '#sheet%s!A1' % str(logfiles.index(item)) text = os.path.split(item)[1] style = Style.easyxf('font: underline single,color blue;') new_row.write(1, Formula('HYPERLINK("%s";"%s")' % (click, text)), style) new_row.write(2, 'sheet' + str(logfiles.index(item))) #creat other sheet out_putlist = get_formatted_in_a_file(item) Write_To_excel(book, 'sheet' + str(logfiles.index(item)), out_putlist)
# else: # pass for row in range(sheet_name_0.nrows): values = [] for col in range(sheet_name_0.ncols): value = sheet_name_0.cell(row, col).value # 员工上班打卡时间 if col == 4: staff_sign_in_time = sheet_name_0.cell(row, col).value if isinstance(staff_sign_in_time, float): staff_sign_in_time = str(staff_sign_in_time) sheet_one.write( row, col, value, Style.easyxf('pattern: pattern solid, fore_colour yellow;' 'align: horiz center;')) else: staff_sign_in_time = staff_sign_in_time.encode('utf-8') if -1 != str.find(staff_sign_in_time, '-'): staff_sign_in_time_info = staff_sign_in_time.split(' ') staff_sign_in_time_date = staff_sign_in_time_info[0] staff_sign_in_time_hour_second = staff_sign_in_time_info[ -1] staff_sign_in_time_hour_second_info = staff_sign_in_time_hour_second.split( ':') staff_sign_in_time_hour = staff_sign_in_time_hour_second_info[ 0] staff_sign_in_time_second = staff_sign_in_time_hour_second_info[ -1] staff_sign_in_time_hour_int = int(staff_sign_in_time_hour) staff_sign_in_time_second_int = int(
ws.row(2).set_cell_number(2,265L) ws.row(2).set_cell_number(3,Decimal('3.65')) ws.row(3).write(0,date(2009,3,18)) ws.row(3).write(1,datetime(2009,3,18,17,0,1)) ws.row(3).write(2,time(17,1)) ws.row(4).set_cell_date(0,date(2009,3,18)) ws.row(4).set_cell_date(1,datetime(2009,3,18,17,0,1)) ws.row(4).set_cell_date(2,time(17,1)) ws.row(5).write(0,False) ws.row(5).write(1,True) ws.row(6).set_cell_boolean(0,False) ws.row(6).set_cell_boolean(1,True) ws.row(7).set_cell_error(0,0x17) ws.row(7).set_cell_error(1,'#NULL!') ws.row(8).write( 0,'',Style.easyxf('pattern: pattern solid, fore_colour green;')) ws.row(8).write( 1,None,Style.easyxf('pattern: pattern solid, fore_colour blue;')) ws.row(9).set_cell_blank( 0,Style.easyxf('pattern: pattern solid, fore_colour yellow;')) ws.row(10).set_cell_mulblanks( 5,10,Style.easyxf('pattern: pattern solid, fore_colour red;') ) wb.save('types.xls')
ws.row(2).set_cell_number(1,15) ws.row(2).set_cell_number(2,265L) ws.row(2).set_cell_number(3,Decimal('3.65')) ws.row(3).write(0,date(2009,3,18)) ws.row(3).write(1,datetime(2009,3,18,17,0,1)) ws.row(3).write(2,time(17,1)) ws.row(4).set_cell_date(0,date(2009,3,18)) ws.row(4).set_cell_date(1,datetime(2009,3,18,17,0,1)) ws.row(4).set_cell_date(2,time(17,1)) ws.row(5).write(0,False) ws.row(5).write(1,True) ws.row(6).set_cell_boolean(0,False) ws.row(6).set_cell_boolean(1,True) ws.row(7).set_cell_error(0,0x17) ws.row(7).set_cell_error(1,'#NULL!') ws.row(8).write(0,'',Style.easyxf('pattern: pattern solid, fore_colour green;')) ws.row(8).write(1,None,Style.easyxf('pattern: pattern solid, fore_colour blue;')) ws.row(9).set_cell_blank(0,Style.easyxf('pattern: pattern solid, fore_colour yellow;')) ws.row(10).set_cell_mulblanks(5,10,Style.easyxf('pattern: pattern solid, fore_colour red;')) # book = Workbook() # sheet1 = book.add_sheet('Sheet 1',cell_overwrite_ok=True) # sheet1.write(0,0,'original') # sheet = book.get_sheet(0) # sheet.write(0,0,'new') # sheet2 = book.add_sheet('Sheet 2') # sheet2.write(0,0,'original') # sheet2.write(0,0,'new')
import urlparse import time from datetime import datetime from xlwt import Workbook, Style # construct the output Excel filename from current date/time today = datetime.today() excelFilename = 'mlb_pitchers_%4d-%02d-%02d.xls' % (today.year, today.month, today.day) BASE_URL = 'http://www.thespread.com' wb = Workbook(encoding='utf-8') sheet1 = wb.add_sheet('Compiled Data') sheet2 = wb.add_sheet('Data Output') sheet3 = wb.add_sheet('Backtest') style_bold = Style.easyxf('font: bold 1') style_over = Style.easyxf('pattern: pattern solid, fore_colour green;') style_under = Style.easyxf('pattern: pattern solid, fore_colour red;') style_push = Style.easyxf('pattern: pattern solid, fore_colour yellow;') pitchers = {} def makeSoup(url): br = mechanize.Browser() br.set_handle_robots(False) br.addheaders = [('User-agent', 'Firefox')] try: response = br.open(url) except: return None return BeautifulSoup(response.read())
rwb = Workbook() ws = rwb.add_sheet('intervals') pre1 = frameIntervals[0] pre2 = frameIntervals[1] incRecord = [] decRecord = [] Record18 = [] Record15 = [] cValue = 0 ws.row(0).write(0, frameIntervals[0]) ws.row(1).write(0, frameIntervals[1]) for i in range(2, len(frameIntervals)-1): cValue = frameIntervals[i] if cValue == pre1 and pre1 == pre2: ws.row(i).write(0, cValue,Style.easyxf('pattern: pattern solid, fore_colour yellow')) incRecord.append(i) elif pre1 == 0.016 and cValue == pre1: ws.row(i).write(0, cValue,Style.easyxf('pattern: pattern solid, fore_colour red')) decRecord.append(i) elif cValue == 0.018: ws.row(i).write(0, cValue,Style.easyxf('pattern: pattern solid, fore_colour blue')) Record18.append(i) elif cValue == 0.015: ws.row(i).write(0, cValue,Style.easyxf('pattern: pattern solid, fore_colour brown')) Record15.append(i) else: ws.row(i).write(0, cValue) pre1 = pre2 pre2 = cValue