C# Excel 시트 여러 개 읽기

1175 단어 EXCEL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
         // Excel 
            string SourceExcelPath = "E:\\C# Projects\\ConsoleApplication1\\ForTesting2.xlsx";
            string StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;"+" Data Source=" + SourceExcelPath + ";"+"Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";// 
            OleDbConnection ExcelConn = new OleDbConnection(StrConn);
            ExcelConn.Open();// 
          // 
            System.Data.DataTable SheetNames = ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[]{null,null,null,"Table"});// 
            string []TableNames=new string[SheetNames.Rows.Count];
            for (int k = 0; k < SheetNames.Rows.Count;++k )
            {
                TableNames[k]=SheetNames.Rows[SheetNames.Rows.Count-k-1]["TABLE_NAME"].ToString();// 
                Console.WriteLine(TableNames[k]);
            }         
        }
    }
}

좋은 웹페이지 즐겨찾기