110,538
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
Excel.Workbook workbook = null;
string str = @"E:\test.xlsx";
try
{
workbook = xlApp.Workbooks.Open(str);
Console.WriteLine("Succeed");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
xlApp.Quit();
if (workbook != null)
{
workbook.Close(null, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
workbook = null;
}
if (xlApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
xlApp = null;
}
GC.Collect();
}
Console.ReadLine();
}
}
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Workbook wBook = null;
Worksheet wSheet = null;
object oMissiong = System.Reflection.Missing.Value;
wBook = app.Workbooks.Open(excelFileName, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong,
oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
wSheet = wBook.Worksheets.get_Item(1);//读取第一张表