-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpythonnet_ver.py
More file actions
34 lines (23 loc) · 1.03 KB
/
pythonnet_ver.py
File metadata and controls
34 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import clr
from System import Activator, Type
from System.Reflection import BindingFlags
def main():
doc = Activator.CreateInstance(Type.GetTypeFromProgID('bpac.Document'))
print("doc: {}".format(doc.__class__))
#=> <class 'System.__ComObject'>
# printers = doc.Printer.GetInstalledPrinters
# => AttributeError: '__ComObject' object has no attribute 'Printer'
printer = doc.GetType().InvokeMember("Printer", BindingFlags.GetProperty, None, doc, None )
print("Printer:{}".format(printer))
# 属性を確認
print(dir(printer))
printers = doc.GetType().InvokeMember("GetInstalledPrinters", BindingFlags.GetProperty, None, printer, None )
print("InstalledPrinters:{}".format(printers))
for p in printers:
print("installed Printer:{}".format(p))
def excel():
xlsx = Activator.CreateInstance(Type.GetTypeFromProgID('Excel.Application'))
print("xlsx: {}".format(xlsx.__class__))
if __name__ == "__main__":
main()
excel()