在要求输入邮箱的文本域,请填写真实的邮件地址。非真实邮件地址,将收不到回复信息。

C#获得Excel第一个工作表的名称

C# 清风 1412℃ 0评论

private string getExcelSheetFirstNameFor(string path) 
{
	string firstName = "";
	Excel.Application objExcelApp = new Application();
	objExcelApp.Visible = false;
	objExcelApp.DisplayAlerts = false;
	Workbooks objWorkbooks = objExcelApp.Workbooks;
	_Workbook objWorkbook = null;
	_Worksheet objWorksheet = null;
	object objMissing = System.Reflection.Missing.Value;
	try 
	{
		objWorkbooks.Open(path, objMissing, true, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, true, objMissing, objMissing, objMissing, objMissing, objMissing);
		objWorksheet = (Worksheet)objWorkbooks.get_Item(1).Worksheets.get_Item(1);
		firstName = objWorksheet.Name;
	}
	catch (Exception ex) 
	{
	}
	finally 
	{
		objWorksheet = null;
		if (objWorkbook != null) 
		{
			objWorkbook.Close(objMissing, objMissing, objMissing);
			objWorkbook = null;
		}
		if (objWorkbooks != null) 
		{
			objWorkbooks.Close();
			objWorkbooks = null;
		}
		if (objExcelApp != null) 
		{
			objExcelApp.Quit();
			objExcelApp = null;
		}
	}
	return firstName;
}



转载请注明:清风亦平凡 » C#获得Excel第一个工作表的名称

喜欢 (1)or分享 (0)
支付宝扫码打赏 支付宝扫码打赏 微信打赏 微信打赏
头像
发表我的评论
取消评论

CAPTCHA Image
Reload Image
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址