Dwin操作EXCEL的一点方法(初学,初用)
1 import tango.io.Stdout;
2 import std.c.time;
3 import dwin.sys.win32.com.Core;
4 import dwin.sys.win32.com.Client;
5
6 void main()
7 {
8 IDispatch excel;
9 excel = coCreate!(IDispatch)("Excel.Application", ExecutionContext.LocalServer);
10
11 if (excel !is null)
12 {
13 scope(exit) {
14 sleep(3);
15 tryRelease(excel);
16 Stdout ("release ok").newline;
17 }
18
19 invokeMember("Visible", DispatchFlags.PutProperty, excel, 1);
20
21 Variant vExcel = invokeMember ("Workbooks", DispatchFlags.GetProperty, excel);
22
23 IDispatch office = vExcel.pdispVal;
24
25 if ( office !is null ) {
26 invokeMember ("Add", DispatchFlags.GetProperty, office);
27 Stdout (" add workbook ok").newline;
28 }
29 else
30 Stdout ("no Workbooks").newline;
31 }
32 else
33 Stdout ("no").newline;
34 }