2012-06-05 2 views
1

나는 Windows 응용 프로그램이 있습니다. 파일을 찾아보고 OpenFileDialog 컨트롤을 사용하여 Excel 파일을 선택합니다. Excel 파일에는 A 열에 전자 메일 ID가 들어 있습니다. 목록 상자에 Excel 파일 열 값을 채우고 싶습니다. 내 컴퓨터에 Office 2003이 설치되어 있습니다. 누군가 제발 도와주세요. 미리 감사드립니다.C를 사용하여 Excel에서 목록 상자를 채우는 방법

+0

[C#에서 Excel 파일 읽기] 가능한 복제본 (http://stackoverflow.com/questions/15828/reading-excel-files-from-c-sharp) –

답변

1

은 참조 :

string connString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=<YourExcelPath>; 
Extended Properties=\"Excel 12.0;HDR=YES;\""; 

OLEDB를 클래스 파일에서 정보를 조회하는 사용 후 :

string selectCmd = "SELECT * FROM <SheetName>"; 

using(OleDbConnection excelConn = new OleDbConnection(connString)) 
{ 
    excelConn.Open(); 
    OleDbCommand command = new OleDbCommand(selectCmd, excelConn); 
    OleDbDataAdapter da = new OleDbDataAdapter(command); 

    DataTable sheetInfo = new DataTable(); 
    dataAdapter.Fill(sheetInfo); 

    //Do something with the data. 
    Bind your control with this datatable here 
} 
Reading Excel files from C#

가 적절한 연결 문자열을 필요 파일을 엑셀에 연결하려면

"YourExcelPath"를 Excel 파일의 경로로 바꿔야합니다.

관련 문제