nanda
nanda

Reputation: 25

How to open MS Excel Workbook 2010 in ToleContainer using delphi 6

I am using TOleContainer to Access Excel from Application. in Olecontainer objects we have MS Excel 2003 worksheet, but I need to open Excel Workbook 2010 version. Can any one help me. Thanks.

Upvotes: 0

Views: 1680

Answers (1)

Ken White
Ken White

Reputation: 125620

Use TOleContainer.CreateObjectFromFile. From the documentation (link to current documentation, but TOleContainer hasn't changed in ages so it's relevant to the version of Delphi you're using):

Creates an embedded OLE object from the contents of a file.

Call CreateObjectFromFile to create an OLE object from the file specified by the FileName parameter. The Iconic parameter indicates whether the object is shown as an icon (true) or displayed as it would be in the server application (false). If there's already an OLE object in the container, it is destroyed and any changes the user made to it are discarded.

A sample of use would be:

OleContainer1.CreateObjectFromFile('C:\temp\test.xlsx', False);

You can also use TOleContainer.CreateObject, if you know the class name of the OLE class. You can find that by using CreateObjectFromFile as I've shown to load an existing Excel file and the reading the TOleContainer.OleClassName. (This is also available in the documentation.) An example using the same version of Excel I have for the above:

OleContainer1.CreateObject('Excel.Sheet.12', False);

Upvotes: 1

Related Questions