PPT转H5系列(一)----判断文件是否pptx文件

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;
}

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值