Felix Zumstein
2014-09-16 16:11:14 UTC
Hi all,
The code snipped below always formats cell A1 correctly as Date in Excel.
However, the second call (2 datetime objects in a list) only formats the
cells as Date on one of my systems, but not on the other one even though
they are essentially the same (Win7 64bit, Excel 2010 32 bit, Anaconda
Python 2.7 64bit, pywin32 v219). In fact, the third call formats the two
cells (A3:B3) correctly on both systems.
I've played around with Regional Settings both on Windows and Excel, made
sure that the post_install script was run for pywin32 and ran makepy.py to
import the Excel Object Model. Does anybody have any idea why the list of
datetime objects doesn't get formatted correctly on Excel?
from win32com.client import dynamic
from datetime import datetime
app = dynamic.Dispatch('Excel.Application')
app.Visible = True
wb = app.Workbooks.Add()
wb.Sheets('Sheet1').Range('A1').Value = datetime(2000, 1, 1) # formats
Excel cell correctly
wb.Sheets('Sheet1').Range('A2:B2').Value = [datetime(2000, 1, 1),
datetime(2000, 1, 1)] # doesn't format the cells
wb.Sheets('Sheet1').Range('A3:B3').Value = [datetime(2000, 1, 1)] #
formats Excel cell correctly
thanks,
Felix
The code snipped below always formats cell A1 correctly as Date in Excel.
However, the second call (2 datetime objects in a list) only formats the
cells as Date on one of my systems, but not on the other one even though
they are essentially the same (Win7 64bit, Excel 2010 32 bit, Anaconda
Python 2.7 64bit, pywin32 v219). In fact, the third call formats the two
cells (A3:B3) correctly on both systems.
I've played around with Regional Settings both on Windows and Excel, made
sure that the post_install script was run for pywin32 and ran makepy.py to
import the Excel Object Model. Does anybody have any idea why the list of
datetime objects doesn't get formatted correctly on Excel?
from win32com.client import dynamic
from datetime import datetime
app = dynamic.Dispatch('Excel.Application')
app.Visible = True
wb = app.Workbooks.Add()
wb.Sheets('Sheet1').Range('A1').Value = datetime(2000, 1, 1) # formats
Excel cell correctly
wb.Sheets('Sheet1').Range('A2:B2').Value = [datetime(2000, 1, 1),
datetime(2000, 1, 1)] # doesn't format the cells
wb.Sheets('Sheet1').Range('A3:B3').Value = [datetime(2000, 1, 1)] #
formats Excel cell correctly
thanks,
Felix