python excel lib (xlwt)

來源:互聯網
上載者:User

具體安裝和使用見文章http://blog.csdn.net/xiarendeniao/article/details/6774520 item44

下面是鳥人寫的一個列印顏色和寬高的指令碼:

#encoding=utf-8from xlwt import Workbook, easyxfdef show_color(sheet):        colNum = 6        width = 5000        height = 500        colors = ['aqua','black','blue','blue_gray','bright_green','brown','coral','cyan_ega','dark_blue','dark_blue_ega','dark_green','dark_green_ega','dark_purple','dark_red',                'dark_red_ega','dark_teal','dark_yellow','gold','gray_ega','gray25','gray40','gray50','gray80','green','ice_blue','indigo','ivory','lavender',                'light_blue','light_green','light_orange','light_turquoise','light_yellow','lime','magenta_ega','ocean_blue','olive_ega','olive_green','orange','pale_blue','periwinkle','pink',                'plum','purple_ega','red','rose','sea_green','silver_ega','sky_blue','tan','teal','teal_ega','turquoise','violet','white','yellow']        for colorIndex in range(len(colors)):                rowIndex = colorIndex / colNum                colIndex = colorIndex - rowIndex*colNum                sheet.col(colIndex).width = width                sheet.row(rowIndex).set_style(easyxf('font:height %s;'%height))                 color = colors[colorIndex]                whiteStyle = easyxf('pattern:pattern solid, fore_colour %s;'                                        'align: vertical center, horizontal center;'                                        'font: bold true, colour white;' % color)                blackStyle = easyxf('pattern:pattern solid, fore_colour %s;'                                        'align: vertical center, horizontal center;'                                        'font: bold true, colour black;' % color)                if color == 'black':                        sheet.write(rowIndex, colIndex, color, style = whiteStyle)                else:                        sheet.write(rowIndex, colIndex, color, style = blackStyle)def show_size(sheet):        widthStart = 100        widthInterval = 100        colNum = 255        heightStart = 100        heightInterval = 5        rowNum = 255        styles = (easyxf('pattern:pattern solid, fore_colour gray50;'                        'align: vertical center, horizontal center;'                        'font: bold true, colour white;'),                easyxf('pattern:pattern solid, fore_colour gray80;'                        'align: vertical center, horizontal center;'                        'font: bold true, colour white;'))        for rowIndex in range(rowNum):                height = heightStart + heightInterval*rowIndex                sheet.row(rowIndex).set_style(easyxf('font:height %s;'%height))                styleIndex = rowIndex%2                for colIndex in range(colNum):                        width = widthStart + widthInterval*colIndex                        sheet.col(colIndex).width = width                        sheet.write(rowIndex, colIndex, '%sx%s'%(width,height), style = styles[styleIndex])                        styleIndex = int(not styleIndex)if __name__ == '__main__':        book = Workbook(encoding='utf-8')        colorSheet = book.add_sheet('colors')        sizeSheet = book.add_sheet('size')        show_color(colorSheet)        show_size(sizeSheet)        styleFile = 'excel_styles.xls'        book.save(styleFile)        print 'saved to "%s"' % styleFile

具體結果見資源檔http://download.csdn.net/detail/xiarendeniao/4867129

顏色:

寬高:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.