接前面一篇文件,先通过COM启动PowerPoint程序
void XmlConverter::StartPowerPointApplication()
{
if (this->m_application_powerpoint.m_lpDispatch == NULL)
{
try
{
if(MyPPT::MyGetActiveObject(this->m_application_powerpoint, "PowerPoint.Application"))
{
std::string strVersion = (LPCSTR)this->m_application_powerpoint.get_Version();
this->m_OfficeVersion = util::StrToDouble(strVersion);
}
else
{
if (MyPPT::MyStartApplication(this->m_application_powerpoint, "91493441-5A91-11CF-8700-00AA0060263B"))
{
std::string strVersion = (LPCSTR)this->m_application_powerpoint.get_Version();
this->m_OfficeVersion = util::StrToDouble(strVersion);
}
}
}
catch(...)
{
if (!MyPPT::MyStartApplication(this->m_application_powerpoint, "91493441-5A91-11CF-8700-00AA0060263B"))
{
std::string strVersion = (LPCSTR)this->m_application_powerpoint.get_Version();
this->m_OfficeVersion = util::StrToDouble(strVersion);
}
}
}
}
用启动的PowerPoint程序打开PPT文件,并获取PPT页的宽高
void XmlConverter::OpenPresentation(string strPPTFilePath)
{
if (strPPTFilePath != "")
{
this->m_strPPTFilePath = strPPTFilePath;
}
//判断待转换的ppt文件是否存在
if (!util::IsFileExists(strPPTFilePath.c_str()))
{
return;
}
this->StartPowerPointApplication/*ced95201f0c0bca6c6e0d9d27fd45cdd2*/();
CPPTPresentations presentations(this->m_application_powerpoint.get_Presentations());//Presentations;
if (presentations.m_lpDispatch == NULL)
{
return;
}
try
{
//COM调用office打开ppt文件
LPDISPATCH pDispatch = NULL;
try
{
pDispatch = presentations.Open(this->m_strPPTFilePath.c_str(), MsoTriState::msoFalse, MsoTriState::msoFalse, MsoTriState::msoFalse);
}
catch(...)
{
pDispatch = presentations.Open2007(this->m_strPPTFilePath.c_str(), MsoTriState::msoFalse, MsoTriState::msoFalse, MsoTriState::msoFalse, MsoTriState::msoTrue);
}
if(pDispatch)
{
this->m_presentation_powerpoint.AttachDispatch(pDispatch);
}
CPPTPageSetup pageSetup(this->m_presentation_powerpoint.get_PageSetup());
this->m_fSlideWidth = pageSetup.get_SlideWidth();
this->m_fSlideHeight = pageSetup.get_SlideHeight();
}
catch (COleException* ex)
{
char szMsg[1024] = {0};
ex->GetErrorMessage(szMsg, sizeof(szMsg) - 1);
throw ex;
}
}
之后就可以用上一篇导出的PowerPoint COM组件类库对PPT文件进行操作,并解析PPT文件动画