文:varlemon |
编辑:EarlGrey |
来源:编程派公众号(ID:codingpy) |
今天介绍一个叫 xlpython 的库,通过它我们可以用 Python 来开发 Excel 的宏脚本,真正实现在 Excel 中调用 Python。
-
pip install pypiwin32 -i https://mirrors.aliyun.com/pypi/simple/
-
pip install pywin32 -i https://mirrors.aliyun.com/pypi/simple/
-
from xlpython import *
-
import random
-
@xlfunc
-
def getRandomBirth():
-
y = random.randint(1980, 2000)
-
m = random.randint(1, 12)
-
d = random.randint(1, 28)
-
return str(y)+ / +str(m)+ / +str(d)
-
@xlfunc
-
def getAge(d):
-
_today = [ 2019, 8, 30 ]
-
_list = str(d).split( / )
-
age = _today[0] - int(_list[0])
-
if _today[1] < int(_list[1]):
-
age -= 1
-
elif _today[1] == int(_list[1]):
-
if _today[2] < int(_list[2]):
-
age -= 1
-
else:
-
pass
-
else:
-
pass
-
return age
-
[https://www.python.org/downloads/windows/]: https://www.python.org/downloads/windows/
-
[https://sourceforge.net/projects/excelpython/files/]: https://sourceforge.net/projects/excelpython/files/
-
https://files.cnblogs.com/files/connect/excelpython-2.0.8.zip