OLE Automation In Microsoft Windows applications programming, OLE Automation is an inter-process communication mechanism based on Component Object Model.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Microsoft Word © Automation from Microsoft Access © by Ofer Shimrat for AUGSD MS Office Versions 2000 & 2002.
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
By Chris Pascucci and FLF
Introduction to Database Processing with ADO.NET.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
ODBC, OLE DB, and ADO Introduction Dr. Ron Eaglin.
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
1 Introducing Database Access from Web Applications by Sally Kyvernitis.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
Overview of ADO.NET with the.NET Framework Scalable Development, Inc. Building systems today that perform tomorrow.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
CIS 451: Using ASP.NET Objects with SQL Dr. Ralph D. Westfall February, 2009.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
Microsoft FrontPage 2003 Illustrated Complete Using Office Components.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
Architectures Classic Client/Server Architecture Classic Web Architecture N-tier (multi-tier) Architecture FEN Databaser og Modellering.
MySQL Connection using ADO.Net Connecting to MySQL from.NET Languages.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
History of Windows Data Sharing Carlotta Eaton Exploring Microsoft Visual Basic 5.0 To insert your company logo on this slide From the Insert Menu Select.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
JDS – VB.NET Skill Session Fall 2004 Presented by YUHAO LIN.
Visual Basic.NET Programming March 3, Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)
Microsoft Excel 2003 Illustrated Complete Data with Other Programs Exchanging.
Accessing Data with Microsoft Visual C# Applications.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
HNDIT Rapid Application Development
2314 – Programming Language Concepts Introduction to ADO.NET.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
ADO.NET in VB.NET 2005 ITE 370 4/26/2017.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
VB.Net. Topics Introduction to VB.Net Creating VB.Net Project in VS 2005 Data types and Operators in VB.Net String Functions Conditions (If Else, Select.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
.NET Data Access and Manipulation
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
Managing, Storing, and Executing DTS Packages
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
Lecture 6 VB.Net SQL Server.
Microsoft FrontPage 2003 Illustrated Complete
VB.NET Using Database.
Tonga Institute of Higher Education
MySQL Connection using ADO.Net
Browser (Client Side) 瀏覽器 (客戶端)
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Presentation transcript:

OLE Automation In Microsoft Windows applications programming, OLE Automation is an inter-process communication mechanism based on Component Object Model (COM) that was intended for use by scripting languages – originally Visual Basic – but now are used by languages run on Windows. It provides an infrastructure whereby applications called automation controllers can access and manipulate shared automation objects that are exported by other applications. It supersedes Dynamic Data Exchange (DDE), an older mechanism for applications to control one another. As with DDE, in OLE Automation the automation controller is the "client" and the application exporting the automation objects is the "server".

OLE DB and ADO

Example OLE DB using System; using System.Data; using System.Data.OleDb; using System.Xml.Serialization; public class MainClass { public static void Main () { // Set Access connection and select strings. // The path to BugTypes.MDB must be changed if you build // the sample from the command line: #if USINGPROJECTSYSTEM string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\BugTypes.MDB"; #else string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BugTypes.MDB"; #endif string strAccessSelect = "SELECT * FROM Categories"; // Create the dataset and add the Categories table to it: DataSet myDataSet = new DataSet(); OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); } catch(Exception ex) { Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message); return; }

try { OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect,myAccessConn); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand); myAccessConn.Open(); myDataAdapter.Fill(myDataSet,"Categories"); } catch (Exception ex) { Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message); return; } finally { myAccessConn.Close(); } // A dataset can contain multiple tables, so let's get them // all into an array: DataTableCollection dta = myDataSet.Tables; foreach (DataTable dt in dta) { Console.WriteLine("Found data table {0}", dt.TableName); }

// The next two lines show two different ways you can get the // count of tables in a dataset: Console.WriteLine("{0} tables in data set", myDataSet.Tables.Count); Console.WriteLine("{0} tables in data set", dta.Count); // The next several lines show how to get information on // a specific table by name from the dataset: Console.WriteLine("{0} rows in Categories table", myDataSet.Tables["Categories"].Rows.Count); // The column info is automatically fetched from the database, // so we can read it here: Console.WriteLine("{0} columns in Categories table", myDataSet.Tables["Categories"].Columns.Count); DataColumnCollection drc = myDataSet.Tables["Categories"].Columns; int i = 0; foreach (DataColumn dc in drc) { // Print the column subscript, then the column's name // and its data type: Console.WriteLine("Column name[{0}] is {1}, of type {2}",i++, dc.ColumnName, dc.DataType); } DataRowCollection dra = myDataSet.Tables["Categories"].Rows; foreach (DataRow dr in dra) { // Print the CategoryID as a subscript, then the CategoryName: Console.WriteLine("CategoryName[{0}] is {1}", dr[0], dr[1]); } }

OLE & Office

Word Object Model

Example- Word Replace - Delphi var WordApp:Olevariant; yourDocFileName:String; re:Variant; cnt,i:integer; begin yourDocFileName:=Edit4.text; WordApp := CreateOLEObject('Word.Application'); WordApp.Documents.Open(yourDocFileName); WordApp.Selection.Find.ClearFormatting; WordApp.Selection.Find.Text :='#pNAME#'; WordApp.Selection.Find.Replacement.Text :=Edit1.Text; WordApp.Selection.Find.Execute(Replace := wdReplaceAll); WordApp.ActiveDocument.SaveAs(Edit5.Text); WordApp.ActiveDocument.Close; WordApp.Documents.Open(Edit5.Text); WordApp.Visible := True; end;

Example Word - Macros Dim myStoryRange As Range For Each myStoryRange In ActiveDocument.StoryRanges With myStoryRange.Find With myStoryRange.Find.Text = "#pNAme#".Text = "#pNAme#".Replacement.Text = "Petur".Replacement.Text = "Petur".Wrap = wdFindContinue.Wrap = wdFindContinue.Execute Replace:=wdReplaceAll.Execute Replace:=wdReplaceAll End With End With Do While Not (myStoryRange.NextStoryRange Is Nothing) Do While Not (myStoryRange.NextStoryRange Is Nothing) Set myStoryRange = myStoryRange.NextStoryRange Set myStoryRange = myStoryRange.NextStoryRange With myStoryRange.Find With myStoryRange.Find.Text = "Edit2".Text = "Edit2".Replacement.Text = "Lisabon".Replacement.Text = "Lisabon".Wrap = wdFindContinue.Wrap = wdFindContinue.Execute Replace:=wdReplaceAll.Execute Replace:=wdReplaceAll End With End With Loop Loop Next myStoryRange End Sub VB

Excel Object Model

Outlook

Example Excel Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet.Cells[1, 1] = " xlWorkBook.SaveAs("csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); MessageBox.Show("Excel file created, you can find the file c:\\csharp-Excel.xls"); Създаване на файл

Excel – Format Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; Excel.Range chartRange ; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //add data xlWorkSheet.Cells[4, 2] = ""; xlWorkSheet.Cells[4, 3] = "Student1"; xlWorkSheet.Cells[4, 4] = "Student2"; xlWorkSheet.Cells[4, 5] = "Student3"; xlWorkSheet.Cells[5, 2] = "Term1"; xlWorkSheet.Cells[5, 3] = "80"; xlWorkSheet.Cells[5, 4] = "65"; xlWorkSheet.Cells[5, 5] = "45"; xlWorkSheet.Cells[6, 2] = "Term2"; xlWorkSheet.Cells[6, 3] = "78"; xlWorkSheet.Cells[6, 4] = "72"; xlWorkSheet.Cells[6, 5] = "60";

… ……………….. xlWorkSheet.get_Range("b2", "e3").Merge(false); chartRange = xlWorkSheet.get_Range("b2", "e3"); chartRange.FormulaR1C1 = "MARK LIST"; chartRange.HorizontalAlignment = 3; chartRange.VerticalAlignment = 3; chartRange = xlWorkSheet.get_Range("b4", "e4"); chartRange.Font.Bold = true; chartRange = xlWorkSheet.get_Range("b9", "e9"); chartRange.Font.Bold = true; chartRange = xlWorkSheet.get_Range("b2", "e9"); chartRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight. xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, Excel. XlColorIndex.xlColorIndexAutomatic); xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat. xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode. xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit();

Insert Picture Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //add some text xlWorkSheet.Cells[1, 1] = " xlWorkSheet.Cells[2, 1] = "Adding picture in Excel File"; xlWorkSheet.Shapes.AddPicture("C:\\csharp-xl-picture.JPG", Microsoft.Office. Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45); xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat. xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode. xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlApp); releaseObject(xlWorkBook); releaseObject(xlWorkSheet); MessageBox.Show ("File created !");

Graphic Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); //add data xlWorkSheet.Cells[1, 1] = ""; xlWorkSheet.Cells[1, 2] = "Student1"; xlWorkSheet.Cells[1, 3] = "Student2"; xlWorkSheet.Cells[1, 4] = "Student3"; xlWorkSheet.Cells[2, 1] = "Term1"; xlWorkSheet.Cells[2, 2] = "80"; xlWorkSheet.Cells[2, 3] = "65"; xlWorkSheet.Cells[2, 4] = "45"; xlWorkSheet.Cells[3, 1] = "Term2"; xlWorkSheet.Cells[3, 2] = "78"; xlWorkSheet.Cells[3, 3] = "72"; xlWorkSheet.Cells[3, 4] = "60"; xlWorkSheet.Cells[4, 1] = "Term3"; xlWorkSheet.Cells[4, 2] = "82"; xlWorkSheet.Cells[4, 3] = "80"; xlWorkSheet.Cells[4, 4] = "65"; xlWorkSheet.Cells[5, 1] = "Term4"; xlWorkSheet.Cells[5, 2] = "75"; xlWorkSheet.Cells[5, 3] = "82"; xlWorkSheet.Cells[5, 4] = "68"; Excel.Range chartRange ; Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing); Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250); Excel.Chart chartPage = myChart.Chart; chartRange = xlWorkSheet.get_Range("A1", "d5"); chartPage.SetSourceData(chartRange, misValue); chartPage.ChartType = Excel.XlChartType.xlColumnClustered; xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat. xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode. xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); MessageBox.Show("Excel file created, you can find the file c:\\csharp.net-informations.xls");

VM & Ole Automation