1、根据文件名获取到文件名后缀,再判断后缀是不是.pptx
2、把pptx文件解压出来,并打开docProps\app.xml文件,得到的内容如下
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Template></Template>
<TotalTime>3189</TotalTime>
<Pages>0</Pages>
<Words>285</Words>
<Characters>0</Characters>
<Application>Microsoft Office PowerPoint</Application>
<DocSecurity>0</DocSecurity>
<PresentationFormat>自定义</PresentationFormat>
<Lines>0</Lines>
<Paragraphs>44</Paragraphs>
<Slides>6</Slides>
<Notes>0</Notes>
<HiddenSlides>0</HiddenSlides>
<MMClips>0</MMClips>
<ScaleCrop>false</ScaleCrop>
<HeadingPairs>
<vt:vector size="6" baseType="variant">
<vt:variant>
<vt:lpstr>已用的字体</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>7</vt:i4>
</vt:variant>
<vt:variant>
<vt:lpstr>主题</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>1</vt:i4>
</vt:variant>
<vt:variant>
<vt:lpstr>幻灯片标题</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>6</vt:i4>
</vt:variant>
</vt:vector>
</HeadingPairs>
<TitlesOfParts>
<vt:vector size="14" baseType="lpstr">
<vt:lpstr>Arial</vt:lpstr>
<vt:lpstr>宋体</vt:lpstr>
<vt:lpstr>微软雅黑</vt:lpstr>
<vt:lpstr>Calibri</vt:lpstr>
<vt:lpstr>华文行楷</vt:lpstr>
<vt:lpstr>楷体_GB2312</vt:lpstr>
<vt:lpstr>Times New Roman</vt:lpstr>
<vt:lpstr>默认设计模板</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
<vt:lpstr>PowerPoint 演示文稿</vt:lpstr>
</vt:vector>
</TitlesOfParts>
<LinksUpToDate>false</LinksUpToDate>
<CharactersWithSpaces>0</CharactersWithSpaces>
<SharedDoc>false</SharedDoc>
<HyperlinksChanged>false</HyperlinksChanged>
<AppVersion>16.0000</AppVersion>
</Properties>
3、可以看到docProps\app.xml内容中的<Properties><Application>内容为Microsoft Office PowerPoint,以此作为依据判断文件为pptx文件
4、本文这里用的xml解析库是tinyxml2,具体的C++代码如下
bool IsPPTXFile(CString csFilePath)
{
bool bPPTXFile = false;
tinyxml2::XMLDocument doc;
if (doc.LoadFile(csXMLPath) != tinyxml2::XML_SUCCESS)
{
break;
}
tinyxml2::XMLElement *pProperties = doc.FirstChildElement("Properties");
if (!pProperties)
{
break;
}
tinyxml2::XMLElement *pApplication = pProperties->FirstChildElement("Application");
if (!pApplication)
{
break;
}
std::string strApplication = pApplication->GetText();
strApplication = util::StrToLowerCase(strApplication);
if (strApplication.find("microsoft office powerpoint") == std::string::npos)
{
if (strApplication.find("microsoft macintosh powerpoint") == std::string::npos)
{
bPPTXFile = false;
}
else
{
bPPTXFile = true;
}
}
else
{
bPPTXFile = true;
}
return bPPTXFile;
}