2012-01-15 8 views
0

특정 위치 (d:\temp\emp.xls)에서 Excel 시트를 연 다음 열 머리글을 굵게 표시하고 파일을 저장해야합니다.C에서 Excel 파일에 액세스하는 방법

나는 그것을하려하지만 파일을 열고 1 행에 액세스하여 C#으로 굵게 표시하는 방법을 얻지 못하고 있습니까?

+0

가능한 중복 http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from- c-sharp) –

+0

SSIS 패키지를 사용하여 데이터를 가져 왔습니다. 이제 Excel 시트에 데이터가 들어 있습니다. 이제 파일을 액세스 할 수 있도록 열 너비를 변경하고 굵게 만들기 위해 스크립트 작업을 작성하고 있습니다. – happysmile

답변

0

문자열 connectionString = "공급자 = Microsoft.Jet.OleDb.4.0; 데이터 원본 = c : \ customers.xls; 확장 속성 = Excel 8.0;";

// Select using a Named Range 
    //string selectString = "SELECT * FROM Customers"; 

    // Select using a Worksheet name 
    string selectString = "SELECT * FROM [Sheet1$]"; 

    OleDbConnection con = new OleDbConnection(connectionString); 
    OleDbCommand cmd = new OleDbCommand(selectString,con); 

    try 
    { 
    con.Open(); 
    OleDbDataReader theData = cmd.ExecuteReader(); 
    while (theData.Read()) 
    { 
     Console.WriteLine("{0}: {1} ({2}) - {3} ({4})", theData.GetString(0),theData.GetString(1),theData.GetString(2),theData.GetString(3),theData.GetString(4)); 
    } 
    } 
    catch (Exception ex) 
    { 
    Console.WriteLine(ex.Message); 
    } 
    finally 
    { 
    con.Dispose(); 
    } 
[C 번호에서 엑셀 (.XLS 및 .XLSX)를 생성 파일] (의
관련 문제