日期:2014-05-18  浏览次数:20844 次

怎样获取excel2007的第一个工作表名呢?
原来2003的工作表能取得,到2007中就不能用了。
急呀,高手帮忙呀。

------解决方案--------------------
C# code

Microsoft.Office.Interop.Excel.Application xApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
                xApp.Visible = false;
                //得到WorkBook对象, 可以用两种方式之一: 下面的是打开已有的文件 
                Microsoft.Office.Interop.Excel.Workbook xBook = xApp.Workbooks._Open(FilePath,
                Missing.Value, Missing.Value, Missing.Value, Missing.Value
                , Missing.Value, Missing.Value, Missing.Value, Missing.Value
                , Missing.Value, Missing.Value, Missing.Value, Missing.Value);

Microsoft.Office.Interop.Excel.Worksheet xSheet = (Microsoft.Office.Interop.Excel.Worksheet)xBook.Sheets[1];

------解决方案--------------------
Microsoft.Office.Interop.Excel.Application obj = default(Microsoft.Office.Interop.Excel.Application);
Microsoft.Office.Interop.Excel.Workbook objWB = default(Microsoft.Office.Interop.Excel.Workbook);
string FirstSheetName = null;
obj = (Microsoft.Office.Interop.Excel.Application)Microsoft.VisualBasic.Interaction.CreateObject("Excel.Application", string.Empty);
objWB = obj.Workbooks.Open(filepath, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
Type.Missing,Type.Missing, Type.Missing, Type.Missing, 
Type.Missing, Type.Missing,Type.Missing, Type.Missing);
FirstSheetName = ((Microsoft.Office.Interop.Excel.Worksheet)objWB.Worksheets[1]).Name;
objWB.Close(Type.Missing, Type.Missing, Type.Missing);
objWB = null;
obj.Quit();
obj = null;