Excel Interop阅读工作表内容

时间:2015-09-12 14:26:13

标签: c# excel c++-cli interop cells

我知道这是一个非常基本的话题,但我已经完成了研究,但还没有找到解决我问题的方法,即在工作表中获取大量单元格的内容。这就是我所拥有的:

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#编写的例子。

此时,我会感激任何他。谢谢!

0 个答案:

没有答案