如何在 C++ Builder 中使用 PowerPoint 自动化?
How to use PowerPoint Automation in C++ Builder?
当我尝试使用变体自动化打开 PowerPoint 文件 (ppt) 时收到此错误消息:
Unknown Name
我试过使用自动化:
// Open PPT File
void TMainForm::OpenPPTFile(UnicodeString APPTFile)
{
UnicodeString ppt_path = ExtractFilePath(Application->ExeName)+"ppt\";
UnicodeString ppt_filename = ppt_path+APPTFile;
Variant PowerPoint;
if ( !DirectoryExists(ppt_path) )
{
Application->MessageBoxW(L"The specified Directory does't exist!", L"Error", MB_OK);
return;
}
if ( !FileExists(ppt_filename) )
{
Application->MessageBoxW(L"The specified File does't exist!", L"Error", MB_OK);
return;
}
PowerPoint = CreateOleObject("PowerPoint.Application");
if ( PowerPoint.IsEmpty() )
{
Application->MessageBoxW(L"Unable to open Powerpoint, please check if installed!", L"Error", MB_OK);
return;
}
PowerPoint.OlePropertySet("Enabled", true);
PowerPoint.OlePropertySet("Visible", true);
PowerPoint.OlePropertyGet("Presentations").OleProcedure("Open", ppt_filename, false, false, true);
}
这段代码给出了上面的错误。
注意:PowerPoint 在后台打开没有任何错误,但 ppt 没有。
当您引用的 属性、函数或方法不存在时,会出现此错误。 Application
对象没有Enabled
属性MSDN. To open ppt
you should use WideString
type for ppt_filename
because this type is compatible with BSTR
type used with COM objects or you should use StringToOleStr().
当我尝试使用变体自动化打开 PowerPoint 文件 (ppt) 时收到此错误消息:
Unknown Name
我试过使用自动化:
// Open PPT File
void TMainForm::OpenPPTFile(UnicodeString APPTFile)
{
UnicodeString ppt_path = ExtractFilePath(Application->ExeName)+"ppt\";
UnicodeString ppt_filename = ppt_path+APPTFile;
Variant PowerPoint;
if ( !DirectoryExists(ppt_path) )
{
Application->MessageBoxW(L"The specified Directory does't exist!", L"Error", MB_OK);
return;
}
if ( !FileExists(ppt_filename) )
{
Application->MessageBoxW(L"The specified File does't exist!", L"Error", MB_OK);
return;
}
PowerPoint = CreateOleObject("PowerPoint.Application");
if ( PowerPoint.IsEmpty() )
{
Application->MessageBoxW(L"Unable to open Powerpoint, please check if installed!", L"Error", MB_OK);
return;
}
PowerPoint.OlePropertySet("Enabled", true);
PowerPoint.OlePropertySet("Visible", true);
PowerPoint.OlePropertyGet("Presentations").OleProcedure("Open", ppt_filename, false, false, true);
}
这段代码给出了上面的错误。 注意:PowerPoint 在后台打开没有任何错误,但 ppt 没有。
当您引用的 属性、函数或方法不存在时,会出现此错误。 Application
对象没有Enabled
属性MSDN. To open ppt
you should use WideString
type for ppt_filename
because this type is compatible with BSTR
type used with COM objects or you should use StringToOleStr().