开发者

win32com - Write String values in Excel sheet

开发者 https://www.devze.com 2023-01-19 19:27 出处:网络
I\'m using win32com to write some dates that I receive from a database, and my problem is that I\'m having values like \'01\' and in Excel is just \'1\' - not \'01\'.

I'm using win32com to write some dates that I receive from a database, and my problem is that I'm having values like '01' and in Excel is just '1' - not '01'. Example:

    b = row[1] # b has the value 01
    c = "-"+b+"-"  # c has value -01-
    sheet.Cells(1,1).Value = b  # I have in Excel '1' ; I've try with str(b), c - but is the same

How can I fix this, to have in Excel 开发者_C百科the value recognize as a String, in this case - 01?

Thanks.


Thanks eumiro for the point

I've found the solution - I'm formating the cells to contain String values:

range = sheet.Range(sheet.Cells(1, 1), sheet.Cells(100, 2) )
range.NumberFormat = '@'

I'm doing this before I'm puting the values in cells and it works ok, now in Excel cells I have String values.

0

精彩评论

暂无评论...
验证码 换一张
取 消