【发布时间】:2015-09-12 14:26:13
【问题描述】:
我知道这是一个非常基本的主题,但我已经进行了研究,但还没有找到解决我的问题的方法,即获取工作表中多个单元格的内容。这就是我所拥有的:
Excel::Application^ ExList = gcnew Excel::ApplicationClass();
ExList->DisplayAlerts = false;
ExList->Visible = false;
Workbook^ Wbook1 = ExList->Workbooks->Open(Glo::m_archive01, Type::Missing, false, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing);
Worksheet^ Wsheet1 = safe_cast<Worksheet^>(ExList->ActiveSheet);
String^ m_new_section;//the variable to be displayed later on by means of MessageBox::Show(m_new_section);.
这是我尝试过的以及我得到的编译器错误:
m_new_section = Cells[5, 2]->Value;
error C2065: 'Cells' : undeclared identifier
error C2227: left of '->Value' must point to class/struct/union/generic type
m_new_section = ExList->Cells[5, 2]
error C2440: '=' : cannot convert from 'System::Object ^' to 'System::String ^'
m_new_section = ExList->Cells[5, 2]->Value;
error C2039: 'Value' : is not a member of 'System::Object'
m_new_section = Wsheet1->Cells[5, 2];
error C2440: '=' : cannot convert from 'System::Object ^' to 'System::String ^'
m_new_section = Wsheet1->Cells[5, 2]->Value;
error C2039: 'Value' : is not a member of 'System::Object'
m_new_section = ExList->Cells[5, 2]->Value.ToString();
error C2039: 'Value' : is not a member of 'System::Object'
error C2228: left of '.ToString' must have class/struct/union
这个确实“有效”
m_new_section = Wsheet1->Cells[5, 2]->ToString();
但所有读取的单元格显示的所有 MessageBox 都是这个字符串:“System._ComObject”。
我错过了什么?参考?就像我之前说的,我是这方面的新手,并且使用 c++/cli 进行编码。我唯一的参考资料是我发现的用 c# 编写的示例。
在这一点上,我会很感激任何帮助。谢谢你!
【问题讨论】:
-
那么,Stokes 先生,您输入了什么,先生?
标签: c# excel c++-cli interop cells