0
데스크톱 응용 프로그램에서 작업 중이며 Excel 파일 가져 오기에 약간의 문제가 있습니다.Excel 파일 가져 오기 - 데이터 형식
모든 것이 좋지만 Excel 시트에서 데이터를 읽을 때 모든 숫자와 알파벳을 읽지 않습니다. 예를 들어, 열의 첫 번째 셀이 숫자이면 해당 열에서 Alphabets을 읽지 않습니다. 해당 열의 유형을 텍스트로 수동 변경하면 모든 것이 좋습니다.
다음은 Excel 시트 데이터를 가져 오기위한 샘플 코드입니다.
아이디어가 있으십니까?
public static DataSet exceldata(string filelocation)
{
DataSet ds = new DataSet();
OleDbCommand excelCommand = new OleDbCommand();
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string excelConnStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 4.0;HDR=YES;IMEX=1;Importmixedtypes=text;typeguessrows=0;\"", filelocation);
OleDbConnection excelConn = new OleDbConnection(excelConnStr);
excelConn.Open();
DataTable dtPatterns = new DataTable();
excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(dtPatterns);
ds.Tables.Add(dtPatterns);
return ds;
}