VS2017导入Office365 Excel.exe时,如何排除引发错误的未用属性
Visual Studio 2017+C++调用Office 365 Excel编译错误排查
正在学习《Financial Instrument Pricing Using C++, 2nd Edition》中的Excel交互相关内容,使用环境为Visual Studio 2017 + Office 365 Excel,参考现有讨论编写了如下测试代码:
#include <iostream> #include "atlsafe.h" #import "D:\\project_CPP\\C++_study\\instrument_pricing\\lib\\mso.dll" rename("DocumentProperties", "DocumentPropertiesXL") rename("RGB", "RGBXL") #import "D:\\project_CPP\\C++_study\\instrument_pricing\\lib\\VBE6EXT.OLB" rename("RGB", "RBGXL") using namespace Office; #import "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE" rename("DialogBox", "DialogBoxXL") rename("RGB", "RGBXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("ReplaceText", "ReplaceTextXL") rename("CopyFile", "CopyFileXL") exclude ("Ifont","IPicture","ISensitivityLabelPolicy") no_dual_interfaces no_function_mapping int main() { std::cout << "Hello World!\n"; system("pause"); }
编译后出现如下错误,这些错误与Office新特性DataPrivacyOptions、SensitivityLabelPolicy相关,不需要使用这些属性,已尝试在#import语句中排除IFont、IPicture、ISensitivityLabelPolicy但问题未解决,希望通过排除这些无用属性解决编译问题:
1>testExcel.cpp 1>d:\project_cpp\c++_study\testexcel\testexcel\testexcel.cpp(9): warning C4192: automatically excluding 'IFont' while importing type library 'C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7353): error C2039: 'SensitivityLabelPolicyPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7353): error C3646: 'SensitivityLabelPolicy': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7353): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7759): error C2039: 'DataPrivacyOptionsPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7759): error C3646: 'DataPrivacyOptions': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7759): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8721): error C2039: 'DataPrivacyOptionsPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8721): error C3646: 'GetDataPrivacyOptions': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8721): error C2059: syntax error: '(' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8721): error C2238: unexpected token(s) preceding ';' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8725): error C2039: 'SensitivityLabelPolicyPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8725): error C3646: 'GetSensitivityLabelPolicy': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8725): error C2059: syntax error: '(' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(8725): error C2238: unexpected token(s) preceding ';' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(10565): error C2039: 'ISensitivityLabelPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(10565): error C3646: 'SensitivityLabel': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(10565): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(11171): error C2039: 'ISensitivityLabelPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(11171): error C3646: 'GetSensitivityLabel': unknown override specifier 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(11171): error C2059: syntax error: '(' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(11171): error C2238: unexpected token(s) preceding ';' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tli(4912): error C2039: 'DataPrivacyOptionsPtr': is not a member of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\mso.tlh(13): note: see declaration of 'Office' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tli(4912): error C2039: 'GetDataPrivacyOptions': is not a member of 'Excel::_Application' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tlh(7264): note: see declaration of 'Excel::_Application' 1>d:\project_cpp\c++_study\testexcel\testexcel\debug\excel.tli(4912): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
内容的提问来源于stack exchange,提问作者jlu999
相关产品推荐
相关产品推荐

