c++11 Excel::Range^和Excel::Worksheet->Columns()

c++11 Excel::Range^和Excel::Worksheet->Columns(),excel,visual-studio,c++-cli,Excel,Visual Studio,C++ Cli,包括我的表格 使用名称空间系统; 使用名称空间Microsoft::Office::Interop::Excel 主要{ Microsoft::Office::Interop::Excel::Application^xlApp=gcnew Microsoft::Office::Interop::Excel::ApplicationClass; Microsoft::Office::Interop::Excel::工作簿^xlBook=gcnew Microsoft::Office::Intero

包括我的表格

使用名称空间系统; 使用名称空间Microsoft::Office::Interop::Excel

主要{ Microsoft::Office::Interop::Excel::Application^xlApp=gcnew Microsoft::Office::Interop::Excel::ApplicationClass; Microsoft::Office::Interop::Excel::工作簿^xlBook=gcnew Microsoft::Office::Interop::Excel::WorkbookClass; Microsoft::Office::Interop::Excel::工作表^xlSheet=gcnew Microsoft::Office::Interop::Excel::WorksheetClass; Microsoft::Office::Interop::Excel::Range ^xlRange=gcnew Microsoft::Office::Interop::Excel::WorksheetClass->UsedRange

xlBook=xlApp->Workbooks->OpenExSheet.xlsm,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing,Type::Missing; 对于xlApp->Worksheets中的每个工作表^工作表{//查看所有工作表 如果工作表->名称==文章{//如果名称='文章',则。。。 工作表->选择真;//选择工作表 xlSheet=单张; } } xlRange=xlSheet->Columns1; xlRange=静态\u castxlSheet->Columns1; xlRange=safe\u castxlSheet->Columns1; xlRange=dynamic\u castxlSheet->Columns1;} 最后4个命令xlRange=。。。生成编译器错误:


在带有static_cast的行中,它表示类型转换无效。在所有其他情况下:对句柄类型的对象调用,而没有相应的运算符或将函数转换为指向函数类型的指针


我不明白为什么。如何将列放入Range^对象?

有什么错误?在static_cast的行中,它显示“无效类型转换”。在所有其他方面:“调用对象到句柄类型,而没有对应的操作符或转换器函数,指向函数类型的指针。C++编译器对具有默认属性的COM互操作类型不太友好,特别是对于范围接口。xlSheet->Columns->Item[1,Type::Missing]是最接近的未测试猜测。实际上最好用C编写。不,这也不行:无法将System::Object^类型的值分配给Microsoft::Office::Interop:Excel::Range类型的任何实体^