엑셀 파일에서 Sheet 이름 얻어오기 위한 함수입니다.
검색을 하다보면 다른 방법도 존재하오니 참고용으로 확인해보세요.
using System.IO;
using System.Data.OleDb;
public string[] GetExcelSheetNames(string excelFileName)
{
OleDbConnection con = null;
DataTable dt = null;
String conStr = "";
if (Path.GetExtension(excelFileName).Equals(".xls"))
{
conStr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + excelFileName + ";Extended Properties=Excel 8.0;";
}
else if (Path.GetExtension(excelFileName).Equals(".xlsx"))
{
conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFileName + ";Extended Properties=Excel 12.0;";
}
con = new OleDbConnection(conStr);
con.Open();
dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
return null;
}
String[] excelSheetNames = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow row in dt.Rows)
{
excelSheetNames[i] = row["TABLE_NAME"].ToString();
i++;
}
return excelSheetNames;
}
'C#' 카테고리의 다른 글
[C#/PDA]Get Serial Port Name 예제 (0) | 2016.02.23 |
---|---|
PDA 동기화(Windows Mobile Device Center) 다운로드 (0) | 2016.02.19 |
[C#]파일 확장자 구하기 예제 (0) | 2016.02.19 |
[C#/PDA]SQLite Sample Source 및 SQLite Browser utility (0) | 2016.02.19 |
[C#]NativeWifi를 이용한 무선랜 정보 얻어오기 예제 (0) | 2016.02.17 |