how to keep define the date format when I write merged cell by xlwt?










0














I want to write a merged cell and keep the date format as "yyyy-mm-dd" in a .xls file, and the api I used is xlwt, but I just couldn't make it. This is the code:



# 创建样式4
style4=XFStyle()
style4.alignment = al3
style4.borders = border2
style4.font = fnt
style4.num_format_str='YYYY年MM月DD日'
# style4=xlwt.easyxf('align: wrap on,horiz left; font:name 宋体,height 220; border: left thin,right thin,top thin,bottom thin')
picpath = 'c:\users\lj\desktop\basic.bmp'
# 插入新内容

newWs.write_merge(0,0,0,cols+2,"交易所交易及场外基金交易投资建议 书",style=style1) # 插入标题,选择样式1
newWs.write_merge(3,3,0,cols+2,'投资顾问:上海金锝资产管理有限公司',style=style3)
newWs.insert_bitmap(picpath,15,0) # 插入图片

for i in range(0,cols):
# 将原数据写入新建行的下方
for rowIndex in range(inserRowNo, oldWbS.nrows): #构建行循环
newWs.write(1, 1, 0, i, '投资建议书执行时间:' + str(date [rowIndex]),style=style4)
#newWs.write_merge(1, 1, 0, cols + 2, '投资建议书执行时间:' + '2018年11月9日', style=style1) # 插入时间,选择样式2
newWs.write_merge(2, 2, 0, cols + 2, '项目:'+str(title[rowIndex]), style= style3)
newWs.write_merge(4, 4, 0, cols+2, '所属合同:' + '《'+str(title[rowIndex])+'投资顾问合同'+'》'+'(合同编号:)', style=style3) # 插入时间,选择样式3
for colIndex in range(oldWbS.ncols): # 对每一行进行列循环
newWs.write(rowIndex+5, colIndex+1, oldWbS.cell(rowIndex, colIndex).value,style=style4)#将原数据以下一行的方式写入新行下方,选择样式2
newWb.save(filename) # 保存数据









share|improve this question























  • You can see how to format your code here, so people can understand what you're asking.
    – Edgar R. Mondragón
    Dec 8 at 2:21















0














I want to write a merged cell and keep the date format as "yyyy-mm-dd" in a .xls file, and the api I used is xlwt, but I just couldn't make it. This is the code:



# 创建样式4
style4=XFStyle()
style4.alignment = al3
style4.borders = border2
style4.font = fnt
style4.num_format_str='YYYY年MM月DD日'
# style4=xlwt.easyxf('align: wrap on,horiz left; font:name 宋体,height 220; border: left thin,right thin,top thin,bottom thin')
picpath = 'c:\users\lj\desktop\basic.bmp'
# 插入新内容

newWs.write_merge(0,0,0,cols+2,"交易所交易及场外基金交易投资建议 书",style=style1) # 插入标题,选择样式1
newWs.write_merge(3,3,0,cols+2,'投资顾问:上海金锝资产管理有限公司',style=style3)
newWs.insert_bitmap(picpath,15,0) # 插入图片

for i in range(0,cols):
# 将原数据写入新建行的下方
for rowIndex in range(inserRowNo, oldWbS.nrows): #构建行循环
newWs.write(1, 1, 0, i, '投资建议书执行时间:' + str(date [rowIndex]),style=style4)
#newWs.write_merge(1, 1, 0, cols + 2, '投资建议书执行时间:' + '2018年11月9日', style=style1) # 插入时间,选择样式2
newWs.write_merge(2, 2, 0, cols + 2, '项目:'+str(title[rowIndex]), style= style3)
newWs.write_merge(4, 4, 0, cols+2, '所属合同:' + '《'+str(title[rowIndex])+'投资顾问合同'+'》'+'(合同编号:)', style=style3) # 插入时间,选择样式3
for colIndex in range(oldWbS.ncols): # 对每一行进行列循环
newWs.write(rowIndex+5, colIndex+1, oldWbS.cell(rowIndex, colIndex).value,style=style4)#将原数据以下一行的方式写入新行下方,选择样式2
newWb.save(filename) # 保存数据









share|improve this question























  • You can see how to format your code here, so people can understand what you're asking.
    – Edgar R. Mondragón
    Dec 8 at 2:21













0












0








0







I want to write a merged cell and keep the date format as "yyyy-mm-dd" in a .xls file, and the api I used is xlwt, but I just couldn't make it. This is the code:



# 创建样式4
style4=XFStyle()
style4.alignment = al3
style4.borders = border2
style4.font = fnt
style4.num_format_str='YYYY年MM月DD日'
# style4=xlwt.easyxf('align: wrap on,horiz left; font:name 宋体,height 220; border: left thin,right thin,top thin,bottom thin')
picpath = 'c:\users\lj\desktop\basic.bmp'
# 插入新内容

newWs.write_merge(0,0,0,cols+2,"交易所交易及场外基金交易投资建议 书",style=style1) # 插入标题,选择样式1
newWs.write_merge(3,3,0,cols+2,'投资顾问:上海金锝资产管理有限公司',style=style3)
newWs.insert_bitmap(picpath,15,0) # 插入图片

for i in range(0,cols):
# 将原数据写入新建行的下方
for rowIndex in range(inserRowNo, oldWbS.nrows): #构建行循环
newWs.write(1, 1, 0, i, '投资建议书执行时间:' + str(date [rowIndex]),style=style4)
#newWs.write_merge(1, 1, 0, cols + 2, '投资建议书执行时间:' + '2018年11月9日', style=style1) # 插入时间,选择样式2
newWs.write_merge(2, 2, 0, cols + 2, '项目:'+str(title[rowIndex]), style= style3)
newWs.write_merge(4, 4, 0, cols+2, '所属合同:' + '《'+str(title[rowIndex])+'投资顾问合同'+'》'+'(合同编号:)', style=style3) # 插入时间,选择样式3
for colIndex in range(oldWbS.ncols): # 对每一行进行列循环
newWs.write(rowIndex+5, colIndex+1, oldWbS.cell(rowIndex, colIndex).value,style=style4)#将原数据以下一行的方式写入新行下方,选择样式2
newWb.save(filename) # 保存数据









share|improve this question















I want to write a merged cell and keep the date format as "yyyy-mm-dd" in a .xls file, and the api I used is xlwt, but I just couldn't make it. This is the code:



# 创建样式4
style4=XFStyle()
style4.alignment = al3
style4.borders = border2
style4.font = fnt
style4.num_format_str='YYYY年MM月DD日'
# style4=xlwt.easyxf('align: wrap on,horiz left; font:name 宋体,height 220; border: left thin,right thin,top thin,bottom thin')
picpath = 'c:\users\lj\desktop\basic.bmp'
# 插入新内容

newWs.write_merge(0,0,0,cols+2,"交易所交易及场外基金交易投资建议 书",style=style1) # 插入标题,选择样式1
newWs.write_merge(3,3,0,cols+2,'投资顾问:上海金锝资产管理有限公司',style=style3)
newWs.insert_bitmap(picpath,15,0) # 插入图片

for i in range(0,cols):
# 将原数据写入新建行的下方
for rowIndex in range(inserRowNo, oldWbS.nrows): #构建行循环
newWs.write(1, 1, 0, i, '投资建议书执行时间:' + str(date [rowIndex]),style=style4)
#newWs.write_merge(1, 1, 0, cols + 2, '投资建议书执行时间:' + '2018年11月9日', style=style1) # 插入时间,选择样式2
newWs.write_merge(2, 2, 0, cols + 2, '项目:'+str(title[rowIndex]), style= style3)
newWs.write_merge(4, 4, 0, cols+2, '所属合同:' + '《'+str(title[rowIndex])+'投资顾问合同'+'》'+'(合同编号:)', style=style3) # 插入时间,选择样式3
for colIndex in range(oldWbS.ncols): # 对每一行进行列循环
newWs.write(rowIndex+5, colIndex+1, oldWbS.cell(rowIndex, colIndex).value,style=style4)#将原数据以下一行的方式写入新行下方,选择样式2
newWb.save(filename) # 保存数据






python date merge format xlwt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 8 at 9:24









Edgar R. Mondragón

1,4301619




1,4301619










asked Nov 11 at 13:01









LJhellboy

62




62











  • You can see how to format your code here, so people can understand what you're asking.
    – Edgar R. Mondragón
    Dec 8 at 2:21
















  • You can see how to format your code here, so people can understand what you're asking.
    – Edgar R. Mondragón
    Dec 8 at 2:21















You can see how to format your code here, so people can understand what you're asking.
– Edgar R. Mondragón
Dec 8 at 2:21




You can see how to format your code here, so people can understand what you're asking.
– Edgar R. Mondragón
Dec 8 at 2:21

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248994%2fhow-to-keep-define-the-date-format-when-i-write-merged-cell-by-xlwt%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248994%2fhow-to-keep-define-the-date-format-when-i-write-merged-cell-by-xlwt%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Darth Vader #20

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Ondo