Created
September 12, 2014 15:15
-
-
Save xingkaixin/5f21e2919cb1189b9f53 to your computer and use it in GitHub Desktop.
fill excel with format sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import xlwt; | |
import xlrd; | |
#import xlutils; | |
from xlutils.copy import copy; | |
# styleBoldRed = xlwt.easyxf('font: color-index red, bold on'); | |
# headerStyle = styleBoldRed; | |
# wb = xlwt.Workbook(); | |
# ws = wb.add_sheet('sheet1'); | |
# ws.write(0, 0, "Header", headerStyle); | |
# ws.write(0, 1, "CatalogNumber", headerStyle); | |
# ws.write(0, 2, "PartNumber", headerStyle); | |
# wb.save('a.xls'); | |
#open existed xls file | |
#newWb = xlutils.copy(gConst['xls']['fileName']); | |
#newWb = copy(gConst['xls']['fileName']); | |
oldWb = xlrd.open_workbook('a.xls', formatting_info=True); | |
print oldWb; #<xlrd.book.Book object at 0x000000000315C940> | |
newWb = copy(oldWb); | |
print newWb; #<xlwt.Workbook.Workbook object at 0x000000000315F470> | |
newWs = newWb.get_sheet(0); | |
newWs.write(2, 0, "value1"); | |
newWs.write(2, 1, "value2"); | |
newWs.write(2, 2, "value3"); | |
print "write new values ok"; | |
newWb.save('b.xls'); | |
print "save with same name ok"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment