新建Win32 Console Application (C#),添加COM引用Microsoft Office Excel 15.0 Object Library (Office 2013对应版本15.0)
完整示例代码如下
using System;
using Microsoft.Office; // Add new reference
namespace ExcelReader
{
class Program
{
static void Main(string[] args)
{
ExcelReader er = new ExcelReader("F:/data.xls");
for(int i=1;i<=er.RowCount;++i)
{
for(int j=1;j<=er.ColCount;++j)
{
Console.Write("{0}\t",er.GetCellContent(i,j));
}
Console.WriteLine();
}
er.Close(); // Exit Excel process and release resources
Console.ReadKey();
}
}
class ExcelReader
{
private Microsoft.Office.Interop.Excel._Application xlsApp = null;
private Microsoft.Office.Interop.Excel.Sheets sheets = null;
private Microsoft.Office.Interop.Excel.Worksh