public static object[,] ReadExcel()
{
// 创建一个Excel Application对象
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
// 打开Excel文件
Workbook excelWorkbook = excelApp.Workbooks.Open(@"C:\Users\111\Desktop\111.xlsx");
// 获取第一个工作表
Worksheet excelWorksheet = excelWorkbook.Sheets[1];
// 获取整个工作表的数据
Range usedRange = excelWorksheet.UsedRange;
object[,] data = usedRange.Value;
// 关闭Excel文件和Application对象
excelWorkbook.Close();
excelApp.Quit();
// 释放Excel对象
Marshal.ReleaseComObject(excelWorksheet);
Marshal.ReleaseComObject(excelWorkbook);
Marshal.ReleaseComObject(excelApp);
return data;
}
C#读取excel数据
最新推荐文章于 2024-08-31 08:30:00 发布