ole

ole Git Source Tree

Root/examples.sce

1//==============================================================================
2// call outlook
3//==============================================================================
4pOutlook = ole_actxserver("Outlook.Application")
5pItem = ole_get(pOutlook, "CreateItem",0)
6ole_set(pItem, "Subject","hello")
7ole_set(pItem, "To","allan.cornet@scilab.org")
8ole_set(pItem, "Body","test send email")
9ole_invoke(pItem, "Display")
10ole_invoke(pItem, "Send")
11ole_delete(pItem)
12ole_delete(pOutlook)
13clear pOutlook pItem
14//==============================================================================
15// example: we call Word
16//==============================================================================
17pWord = ole_actxserver("Word.Application")
18ole_set(pWord, "Visible", 1)
19pDocs = ole_get(pWord, "Documents")
20p= ole_invoke( pDocs, "Add")
21pSelection = ole_invoke(pWord, "Selection")
22ole_set(pSelection,"Text","Hello text in Word")
23pActiveDocument = ole_get(pWord, "ActiveDocument")
24ole_invoke(pActiveDocument, "SaveAs",TMPDIR + "/foo.doc")
25ole_invoke(pWord, "Quit")
26ole_delete()
27clear pWord pDocs pSelection pActiveDocument
28//==============================================================================
29// read Word document
30//==============================================================================
31pWord = ole_actxserver("Word.Application")
32ole_set(pWord, "Visible", 1)
33pDocuments = ole_get(pWord, "Documents")
34ole_invoke(pDocuments, "Open",TMPDIR + "/foo.doc");
35pActiveDocument = ole_get(pWord, "ActiveDocument");
36pContent = ole_invoke(pActiveDocument,'Content');
37pText = ole_invoke(pContent,'Text');
38ole_invoke(pWord, "Quit");
39ole_delete()
40clear pWord pDocuments pActiveDocument pContent pText
41//==============================================================================
42// example: we call Internet Explorer
43//==============================================================================
44pIE = ole_actxserver("InternetExplorer.Application")
45ole_invoke(pIE,"Navigate","http://www.scilab.org")
46ole_set(pIE,"Visible",%t)
47ole_invoke(pIE,"Quit")
48ole_delete(pIE)
49clear pIE
50//==============================================================================
51// example: we call Windows Player
52//==============================================================================
53pWMP = ole_actxserver("Wmplayer.ocx")
54ole_invoke(pWMP, "openPlayer", ole_getOlePath() + "demos/newsradio.mp3");
55ole_delete(pWMP)
56clear pWMP
57//==============================================================================
58// example: we call VBScript
59//==============================================================================
60pScript = ole_actxserver('MSScriptControl.ScriptControl')
61ole_set(pScript, 'Language', 'VBScript')
62ole_invoke(pScript,'Eval','MsgBox(""Hello world"")');
63r = ole_invoke(pScript,'Eval','68 + 1')
64ole_invoke(pScript,'Eval','MsgBox(""Nice MessageBox ?"",vbYesNo)')
65ole_delete(pScript)
66//==============================================================================
67// example: we call a database via ADODB.Connection
68//==============================================================================
69// Require a database engine installed on your PC
70// A Few example strings for common databases:
71// MS SQL Server - PROVIDER=SQLOLEDB; Data Source=myServerAddress; Initial Catalog=myDataBase; User Id=myUsername; Password=myPassword;
72// MySQL - driver=MySQL ODBC 3.51 Driver; Server=myServerAddress; Database=myDataBase; UID=username; PWD=password;
73// Access - PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\mydatabase.mdb;User Id=myUsername; Password=myPassword;
74// Access 2007 - PROVIDER=Microsoft.ACE.OLEDB.12.0; Data Source=C:\mydatabase.accdb; Persist Security Info=False;
75// Oracle - PROVIDER=OraOLEDB.Oracle; Data Source=MyOracleDB; User Id=myUsername; Password=myPassword;
76pConn = ole_actxserver('ADODB.Connection')
77commandInvoke = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + ole_getOlePath() + "demos/adotest.mdb" + ';User Id=admin;Password=;'
78ole_set(pConn,'CursorLocation',3)
79ole_invoke(pConn, 'Open', commandInvoke);
80ole_set(pConn,'CommandTimeout',60)
81sqlQuery = 'select LASTNAME from TestTable';
82ole_invoke(pConn,'BeginTrans');
83pData = ole_invoke(pConn, 'Execute', sqlQuery);
84ole_invoke(pConn,'CommitTrans');
85ole_get(pData,'recordcount')
86data = ole_invoke(pData, 'getrows')
87// another request
88sqlQuery = 'select * from TestTable order by lastname, firstname';
89ole_invoke(pConn,'BeginTrans');
90pData = ole_invoke(pConn, 'Execute', sqlQuery);
91ole_invoke(pConn,'CommitTrans');
92ole_get(pData,'recordcount')
93data = ole_invoke(pData, 'getrows')
94//==============================================================================
95// Example Scilab calls TextToSpeech
96//==============================================================================
97pTextToSpeech = ole_actxserver("Sapi.SpVoice")
98ole_invoke(pTextToSpeech ,"Speak","Hello!!! Scilab uses TextToSpeech by COM Object")
99//==============================================================================
100// Call LabVIEW
101pLabVIEW = ole_actxserver('Labview.Application')
102viPath = 'Scilab SignalGen-Analysis.vi'
103pVI = ole_invoke(pLabVIEW, "GetVIReference", viPath)
104ole_set(pVI,'FPWinOpen', %t)
105ole_invoke(pVI, 'Call')
106//==============================================================================
107// Read a xml file
108//==============================================================================
109xmlFileName = ole_getOlePath() + "demos/TheSimpsons.xml";
110xmlDoc = ole_actxserver( 'Microsoft.XMLDOM');
111
112// load xml file in memory
113ole_set(xmlDoc, 'async', "false");
114ole_invoke(xmlDoc, 'load', xmlFileName);
115
116// plain text
117ole_get(xmlDoc,'text')
118
119// Get Name of Characters
120oElement = ole_get(xmlDoc,'documentElement');
121x = ole_invoke(oElement, 'getElementsByTagName' ,"name");
122Lx = ole_get(x,'length');
123for i = 0:Lx-1
124 pItem = ole_get(x, 'item', i);
125 disp(ole_get(pItem,'text'));
126end
127
128// Get Firstname of Characters
129oElement = ole_get(xmlDoc,'documentElement');
130x = ole_invoke(oElement, 'getElementsByTagName' ,"firstname");
131Lx = ole_get(x,'length');
132for i = 0:Lx-1
133 pItem = ole_get(x, 'item', i);
134 disp(ole_get(pItem,'text'));
135end
136//==============================================================================
137// write a xml file
138xmlDoc = ole_actxserver("Microsoft.XMLDOM")
139
140// create root element
141oRoot = ole_invoke(xmlDoc,"createElement","Root");
142ole_invoke(xmlDoc,"appendChild",oRoot);
143
144// add element
145oElement = ole_invoke(xmlDoc, "selectSingleNode", "Root");
146// create a child
147oElement = ole_invoke(xmlDoc, "createElement" , "element");
148
149pdocumentElement = ole_get(xmlDoc, "documentElement");
150// add child to root element
151ole_invoke(pdocumentElement, "appendChild", oElement);
152
153oName = ole_invoke(xmlDoc,"createElement","name");
154ole_set(oName,"Text", "CORNET");
155ole_invoke(oElement, "appendChild", oName);
156
157oFirstname = ole_invoke(xmlDoc,"createElement","firstname");
158ole_set(oFirstname,"Text", "Allan");
159ole_invoke(oElement, "appendChild", oFirstname);
160
161// Save file
162mdelete(TMPDIR + "/write.xml");
163ole_invoke(xmlDoc, "Save", TMPDIR + "/write.xml");
164disp(mgetl(TMPDIR + "/write.xml"))
165//==============================================================================

Archive Download this file

Branches