I'm trying to figure out xlwings. I have the following python code:
from xlwings import xlfunc
from datetime import timedelta, datetime
@xlfunc
def convert(gmt):
gmtValue = datetime(int(gmt[6:10]), int(gmt[3:5]), int(gmt[0:2]), int(gmt[11:13]), int(gmt[14:16]), int(gmt[17:19]))
localTime = gmtValue - timedelta(seconds=(6*3600))
return localTime
All it does is take a time stamp string such as 05/01/2016 14:25:56 GMT and pulls off the GMT and converts it into local time (central time for the US.) I'm trying to use that code along with:
Sub convertToLocal()
RunPython(“import converToLocal; convertToLocal.convert(gmt)”)
End Sub
To make a user defined function but Excel doesn't seem to recognize the python code even though I have the xlwings.bas module imported. The only error I get is “Compile error: Expected end of Statement.” Which I think just means Excel doesn't recognize the python code. Any idea how to fix it? Also, what is the correct way to pass the contents of a cell into the python code?