데이터gridview로 EXCEL 데이터 가져오기

1451 단어 C#
using System.Data;
using System.Data.OleDb;

string strPath;// 

private void  btnExcel_Click(object sender,EventArgs e)
{
    OpenFileDialog  ofd = new OpenFileDialog();
    ofd.Filter = "Excel |*.xlsx";
    if(ofd.ShowDialog() == DialogResult.OK)
    {
    	try
    	{
    	   strPath = ofd.FileName;
    	   String connStr = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source=" + strPath + ";Extended Properties = 'Excel 12.0 Xml;HDR = NO;IMEX=1;READONLY=TRUE'";
    	   OleDbConnection conn = new OleDbConnection(connStr);
    	   conn.Open();
    	   // EXCEL , Sheet , , 
    	   DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[]{null,null,null,"Table"});
    	   // EXCEL 
    	   string[] strTableNames = new string[dtSheetName.Rows.Count];
    	   for(int k = 0; k

좋은 웹페이지 즐겨찾기