无法获得Excel单元格值? (Microsoft.Interop.Office.Excel) [英] Can't get excel cell values? (Microsoft.Interop.Office.Excel)

查看:94
本文介绍了无法获得Excel单元格值? (Microsoft.Interop.Office.Excel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我试图使用命名空间Microsoft.Interop.Office.Excel将Excel单元格值读取到Windows窗体应用程序.但是我很困惑.

我的代码:

Hello friends,

I tried to use the namespace Microsoft.Interop.Office.Excel to read excel cell values to my windows forms application. But I got confusion.

My code:

using namespace Microsoft::Office::Interop::Excel;

#define Excel Microsoft::Office::Interop::Excel
.
.
.

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  Excel::Application^ xlApp =gcnew Excel::ApplicationClass();

  Excel::Workbook^ mybook = xlApp->Workbooks->Open("C:\\Liste.xlsx",Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing, Type::Missing,Type::Missing, Type::Missing);

  xlApp->Visible = false;

  Excel::Worksheet^ mysheet= safe_cast<Worksheet^>(xlApp->ActiveSheet);
  
  mysheet = (Excel::Worksheet^)mybook->Worksheets->Item[1]; 
  
  String^ tmp=mysheet->Cells[2, 3]->ToString();
}



没有错误.但是我为"tmp"获得的始终是"System._ComObject".
不是所期望的,也是打开的xlsx-File中第2行,第3列的值.

我无法理解.



It has no error. But what I get for the "tmp" is always a "System._ComObject".
Not what is expected, also the value of the row 2, column 3 from the opened xlsx-File.

I couldn''t unterstand it. Could you help?

推荐答案

看看 ^ ]在CodeProject上;可能会对您有所帮助.
Take a look at Accessing Excel Spreadsheets via C++[^] here on CodeProject; it may help you.


这篇关于无法获得Excel单元格值? (Microsoft.Interop.Office.Excel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆