PPT转H5系列(四)----通过COM调用PowerPoint打开PPT文件

文章介绍了如何通过COM接口启动PowerPoint程序,检查Office版本,然后打开指定的PPT文件,并获取每一页的宽度和高度,以便后续处理,包括动画解析。
摘要由CSDN通过智能技术生成

接前面一篇文件,先通过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文件动画

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值