【发布时间】:2013-09-17 23:49:33
【问题描述】:
我想打印网络共享(M:驱动器)上的剩余空间量(以 GB 为单位),然后获取该值并将其添加到 Excel 电子表格中。我对编程很陌生,需要我能得到的所有帮助!
提前致谢
编辑:
这是我到目前为止所做的。
import ctypes
from win32com.client import Dispatch
import pythoncom
def drivespace():
#get space in bytes
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(u'M:\\'), None, None ctypes.pointer(free_bytes))
#calculate space in GB
free_GB = free_bytes.value/1024/1024/1024
print(free_GB)
#input data to Excel
xl = Dispatch ('Excel.Application')
xl.visible = 0
xl.Workbooks.Add (r'C:\Location\Location1\Location2\Book1.xlsm')
xl.Run('Down1') #macro inside the workbook, just to move the cell down 1 row
#here is where I need some help... something to input the data to the active cell
#xl.Cells( ?? ACTIVE CELL HERE BUT DON'T KNOW HOW ?? ).value=(free_GB)
xl.Quit()
#release held Excel process
pythoncom.CoUninitialize()
所以基本上,除了将数据实际打印到活动单元格之外,我已经对所有内容进行了排序。有没有人有任何 pywin32 知识可以帮助我做到这一点?
非常感谢!
【问题讨论】:
-
到目前为止,您尝试过吗?什么有效,什么无效?
-
我已经通过解决方案回滚了您对问题的替换。请找到your solution in the revision history 并将其作为自己的答案发布。
标签: python excel pywin32 python-3.3