Пример #1
0
def sandbox():
    #set attributes for workbook
    fnt = Font()
    fnt.name, fnt.colour_index, fnt.bold, fnt._weight = 'Arial',0x08,False,0x0190
    borders = Borders()
    borders.left, borders.right, borders.top, borders.bottom = 0,0,0,0
    al = Alignment()
    al.horz, al.vert = Alignment.HORZ_CENTER,Alignment.VERT_CENTER
    style = XFStyle()
    style.font, style.borders,style.alignment = fnt,borders,al
    # create wb instance
    wb = Workbook()
    #add a sheet for each csv file being imported to excel
    s = util.GetFileListing('Note*.csv')
    csv_files = s.sys_cmd.output
    worksheet_titles = [ ':'.join(a_file.split(':')[1:-2]) for a_file in csv_files ]
    ws_list = [ wb.add_sheet(ws_title) for ws_title in worksheet_titles ]
    F = util.FileEdit(csv_titles)
    for ws,f in zip(ws_list,F.file_utils):
        a_list = [ a_row.rstrip().split(',') for a_row in f.contents ]
        for a_row,a_line in enumerate(a_list):
            for a_col,a_cell in enumerate(a_line): ws.write(a_row,a_col,a_cell,style)

    wb.save('chk_out.xls')
Пример #2
0
def returnStyle():
    borders = Borders()
    borders.left = 0
    borders.right = 0
    borders.top = 0
    borders.bottom = 0
    #borders.Font.Size = 10
    borders.Font = "10"

    al = Alignment()
    al.horz = Alignment.HORZ_CENTER
    al.vert = Alignment.VERT_CENTER

    style = XFStyle()
    style.borders = borders
    style.alignment = al
    return style
Пример #3
0
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os
import os.path
import re
import tempfile
from datetime import datetime, timedelta

from pyExcelerator import Workbook, Borders, XFStyle, Alignment
from pymongo import Connection

one_hour = timedelta(hours=1)
borders = Borders()
borders.left = 1
borders.right = 1
borders.top = 1
borders.bottom = 1

align = Alignment()
align.horz = Alignment.HORZ_CENTER
align.vert = Alignment.VERT_CENTER

style = XFStyle()
style.borders = borders

# center style
cs = XFStyle()
cs.borders = borders
cs.alignment = align
Пример #4
0
    def setup_timetable_worksheet(self,title,base_offsets,maxcells):
        h1 = []
        h2 = []
        h1.append(title)
        h2.extend(['Monday','Tuesday','Wednesday','Thursday','Friday'])
        labels = ['1st period','2nd period','3rd period','4th period','5th period']
        
        times = ['(8:45 - 10:15)','(10:30 - 12:00)','(13:00 - 14:30)','(14:45 - 16:15)','(16:30 - 18:00)']

        h1Style = XFStyle()
        
        font = Font()
        font.height = 300
        font.bold = True
        
        align = Alignment()
        align.horz = Alignment.HORZ_CENTER
        
        h1Style.font = font
        h1Style.alignment = align
        
        h2Style = XFStyle()
        align = Alignment()
        align.rota = 30
        align.horz = Alignment.HORZ_CENTER
        align.vert = Alignment.VERT_CENTER
        h2Style.alignment = align

        borders = Borders()
        borders.bottom = Borders.THIN
        h2Style.borders = borders        
        
        labelStyle = XFStyle()
        borders = Borders()
        borders.bottom = Borders.THIN
        borders.top = Borders.THIN
        borders.left = Borders.THIN
        borders.right = Borders.THIN
        labelStyle.borders = borders
        
        align = Alignment()
        align.rota = 90
        align.horz = Alignment.HORZ_CENTER
        align.vert = Alignment.VERT_CENTER
        labelStyle.alignment = align
            


        self.ws.write_merge(0,0,0,5,title,h1Style)
        
        for pos in range (0,5,1):
            self.ws.write(1,pos+1,h2[pos],h2Style)
        self.ws.write(1,0,'',h2Style)
        for pos in range(0,5,1):
            base_offset = base_offsets[pos]
            offset = maxcells[pos]

            for r in range(2+base_offset,2+base_offset+offset,1):
                row = self.ws.row(r)
                row.height = 5000/offset
                #row.has_default_height = False
            
            text = '%s\n%s' % (labels[pos],times[pos])
            print "base_offset: %d" % (base_offset,)
            print "offset: %d" % (offset,)
            self.ws.write_merge(2+base_offset,2+base_offset+offset-1,0,1,text,labelStyle)
            #self.ws.write_merge(2+base_offset,2+base_offset+offset,0,0,text,labelStyle)

        self.ws.col(0).width = 1200
        for pos in range(1,6,1):    
            self.ws.col(pos).width = 5500

        #self.ws.row(10).has_default_height = False
        self.ws.row(10).height = 400