zoukankan      html  css  js  c++  java
  • C++ 保存Excel文件(带密码保护)

    最近有客户需求报表保存为xls的功能,需要保存的文件设置密码保护,特进行尝试!

    Workbook.SaveAs method (Excel)

    参数详情:https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.saveas

     C++ Code 
    1
    2
    3
    4
    5
    6
     
    void SaveAs(VARIANT &Filename, VARIANT &FileFormat, VARIANT &Password, VARIANT &WriteResPassword, VARIANT &ReadOnlyRecommended, VARIANT &CreateBackup, long AccessMode, VARIANT &ConflictResolution, VARIANT &AddToMru, VARIANT &TextCodepage, VARIANT &TextVisualLayout, VARIANT &Local)
    {
        
    static BYTE parms[] = VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_I4 VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT ;
        InvokeHelper(0x785, DISPATCH_METHOD, VT_EMPTY, 
    NULL, parms, &Filename, &FileFormat, &Password, &WriteResPassword, &ReadOnlyRecommended, &CreateBackup, AccessMode, &ConflictResolution, &AddToMru, &TextCodepage, &TextVisualLayout, &Local);
    }

    调用实例:

     C++ Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    BOOL bReadOnlyRecommended = TRUE;
    BOOL bCreateBackup = TRUE;
    BOOL bLocal = TRUE;
    CString strXlsPath = _T("C:\test.xls");
    m_book.SaveAs(  _variant_t(strXlsPath),                         
    // Filename
                    _variant_t(-4143)/*xlWorkbookNormal*/,          // FileFormat
                    _variant_t(_T("123")),                          // Password
                    _variant_t(_T("123")),                          // WriteResPassword
                    _variant_t(bReadOnlyRecommended),               // ReadOnlyRecommended
                    _variant_t(bCreateBackup),                      // CreateBackup
                    _variant_t(2)/*xlShared*/,                      // AccessMode
                    _variant_t(2)/*xlLocalSessionChanges*/,         // ConflictResolution
                    vtMissing, vtMissing, vtMissing,
                    _variant_t(bLocal));                            
    // Local

    最终成功打开:

  • 相关阅读:
    自己在安装centos 系统时, 是使用英文安装 成功,现在系统语言为英语,如何设置为中文?
    【转】HTML5的语音输入 渐进使用HTML5语言识别, so easy!
    基于layer简单的弹层封装
    条码扫描仪前端驱动
    JavaScript 生成Guid函数
    数据库连接字符串
    IDatabaseInitializer<TContext>接口研究
    async与await线程分配研究
    AsyncLocal<T>与ThreadLocal<T>区别研究
    entity framework core 2.0 & sqlite 配置教程
  • 原文地址:https://www.cnblogs.com/MakeView660/p/10191031.html
Copyright © 2011-2022 走看看