简体   繁体   English

C# 从 VS2010 中的单元格读取 Excel 数据

[英]C# Reading Excel Data From Cells in VS2010

I am writing a C# Console Application and I am correctly opening an Excel file.我正在编写一个 C# 控制台应用程序,并且我正在正确打开一个 Excel 文件。 I just can't figure out how to read data from cells and copy it into an array.我只是不知道如何从单元格中读取数据并将其复制到数组中。 Most of the code I have found list examples that won't work with VS 2010. It appears they have changed how to read cell data in every version.我发现的大多数代码都列出了不适用于 VS 2010 的示例。似乎它们已经改变了在每个版本中读取单元格数据的方式。 I am wanting to read a variable amount of rows depending on how long the data goes.我想根据数据的持续时间读取可变数量的行。 I am wanting to read cells [B8]-[*8].我想读取单元格 [B8]-[*8]。

I have spend a couple of days on this without much luck.我花了几天时间在这上面没有太多运气。

Thanks very much, BuZzZzJaY非常感谢, BuZzZzJaY

You can use this method workSheet.get_Range("A1", "A1").EntireRow.EntireColumn您可以使用此方法 workSheet.get_Range("A1", "A1").EntireRow.EntireColumn

use bellow code this is 2d array.使用下面的代码这是二维数组。 Iterate in this在此迭代

Object[,] obj = (object[,])sheet.get_Range("A1", "B4").Value2;对象[,] obj = (object[,])sheet.get_Range("A1", "B4").Value2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM