您的位置:首页 > 编程语言 > C#

在控制台读取Excel的方法,可根据自身需要修改使用以适应其它平台使用。

2016-10-02 10:37 295 查看
string filepath = @"D:\wAngran's\文档\Desktop\tempS\亲情1+1_isProc.xlsx";

Microsoft.Office.Interop.Excel.Application ea = new ApplicationClass();

ea.Workbooks.Open(filepath, 3, true, 2, string.Empty, string.Empty, true, XlPlatform.xlWindows, ";", null, null, null, null, null, null);

Workbook wb = ea.Workbooks[1];

Worksheet ws = (Worksheet)wb.Sheets[2];

Microsoft.Office.Interop.Excel.Range re = ws.UsedRange;

int down = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlDown).Row;

int right = re.get_End(Microsoft.Office.Interop.Excel.XlDirection.xlToRight).Column;

for (int row_index = 1; row_index < down; row_index++)

{

for (int cel_index = 1; cel_index < right; cel_index++)

{

re = (Range)ws.Cells[row_index, cel_index];

Console.Write(re.Text + "\t");

//re.set_Value(null, cel_index);

}

Console.Write("\n");

}

//if (System.IO.File.Exists(filepath))

// System.IO.File.Delete(filepath);

wb.Close(true, filepath, null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# Excel
相关文章推荐