标签:++ excel file 文件 count column mis length get
public List
{
List
//创建 Excel对象
Microsoft.Office.Interop.Excel.Application App = new Microsoft.Office.Interop.Excel.Application();
//获取缺少的object类型值
object missing = Missing.Value;
//打开指定的Excel文件
Microsoft.Office.Interop.Excel.Workbook openwb = App.Workbooks.Open(ExcelName, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
//获取选选择的工作表
Microsoft.Office.Interop.Excel.Worksheet ws = ((Microsoft.Office.Interop.Excel.Worksheet)openwb.Worksheets["Sheet1"]);//方法一:指定工作表名称读取
//Worksheet ws = (Worksheet)openwb.Worksheets.get_Item(1);
//获取工作表中的行数
int rows = ws.UsedRange.Rows.Count;
//获取工作表中的列数
int columns = ws.UsedRange.Columns.Count;
Console.WriteLine("请输入你要获取哪列数据");
int column = Convert.ToInt16(1);
//提取对应行列的数据并将其存入数组中
for (int i = 2; i < rows; i++)
{
string aName = ((Microsoft.Office.Interop.Excel.Range)ws.Cells[i, column]).Text.ToString();
Console.WriteLine("读取的数据:" + aName);//测试是否获得数据
string[] fileStr = aName.Split(‘.‘);
if (fileStr.Length>1)
{
if (fileStr[1]== "xml")
{
ColumnDB.Add(aName);
}
}
}
return ColumnDB;
}
标签:++ excel file 文件 count column mis length get
原文地址:https://www.cnblogs.com/LCLBook/p/13218017.html