2015-09-12 9 views
-1

Я знаю, что это очень простая тема, но я провел исследование и еще не нашел решения своей проблемы, которая получает содержимое нескольких ячеек на листе. Это то, что у меня есть:Презентация рабочего листа Excel Interop

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#.

На данный момент, я был бы признателен за любой heLp. СПАСИБО!

+1

Итак, мистер Стоукс, что вы вводите, сэр? –

ответ

0

«Забавно, как время учит нас терпению. Чем старше мы становимся, тем больше наша способность ждать» - Элизабет Тейлор.

String^ m_new_section; 
Excel::Range^ er1 = Wsheet1->Range["E2:E2", Type::Missing]; 
m_new_section = er1->Text->ToString(); 

Это все, что нужно было сделать. Опять же, СПАСИБО ЗА ВАШЕ ВРЕМЯ! Спасибо, Крис!

Смежные вопросы