简体   繁体   English

如何使用Delphi 6在ToleContainer中打开MS Excel Workbook 2010

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

I am using TOleContainer to Access Excel from Application. 我正在使用TOleContainer从应用程序访问Excel。 in Olecontainer objects we have MS Excel 2003 worksheet, but I need to open Excel Workbook 2010 version. 在Olecontainer对象中,我们有MS Excel 2003工作表,但我需要打开Excel Workbook 2010版本。 Can any one help me. 谁能帮我。 Thanks. 谢谢。

Use TOleContainer.CreateObjectFromFile . 使用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): 文档 (链接到当前文档,但是TOleContainer年龄没有变化,因此它与您使用的Delphi版本有关):

Creates an embedded OLE object from the contents of a file. 根据文件的内容创建嵌入式OLE对象。

Call CreateObjectFromFile to create an OLE object from the file specified by the FileName parameter. 调用CreateObjectFromFile从FileName参数指定的文件中创建OLE对象。 The Iconic parameter indicates whether the object is shown as an icon (true) or displayed as it would be in the server application (false). Iconic参数指示对象是显示为图标(true)还是显示为在服务器应用程序中的显示形式(false)。 If there's already an OLE object in the container, it is destroyed and any changes the user made to it are discarded. 如果容器中已经有一个OLE对象,则该对象将被销毁,并且用户对其进行的任何更改都将被丢弃。

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. 如果您知道OLE类的类名,也可以使用TOleContainer.CreateObject You can find that by using CreateObjectFromFile as I've shown to load an existing Excel file and the reading the TOleContainer.OleClassName . 您可以通过使用CreateObjectFromFile来找到该文件,如所示,它可以加载现有的Excel文件并读取TOleContainer.OleClassName (This is also available in the documentation .) An example using the same version of Excel I have for the above: (这也可以在文档中找到 。)一个示例,它使用与我上面的Excel版本相同的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM