Riferimenti stringa connessione
http://msdn.microsoft.com/it-it/library/ms254978(VS.80).aspx

Extended Properties imposta le proprietà specifiche di Excel.
"HDR=Yes;" indica che la prima riga contiene nomi di colonne e non dati,
"IMEX=1;" indica al driver di leggere sempre come testo colonne di dati misti.

ES:

   1:  
2: Es:
3:
   4:  // carico il file...
   5:  FileUpload1.SaveAs(
   6: Server.MapPath("/" + FileUpload1.FileName));
   7:   

   8:  // importo i dati ...
   9:  // Excel 2007
  10:  // ES:
  11:  // Provider=Microsoft.ACE.OLEDB.12.0;Data Source=
:\myFolder\myExcel2007file.xlsx;
  12:  // Extended Properties="Excel 12.0 Xml;HDR=YES";
  13:   
  14:  // excel 2003 
  15:string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +

  16:"Data Source=" + Server.MapPath("/" + FileUpload1.FileName)
+ ";" +
  17:  "Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
  18:   
  19:  OleDbDataAdapter da = new OleDbDataAdapter(
"SELECT * FROM [Sheet1$]", strConn);
  20:   
  21:  DataSet ds = new DataSet();
  22:  da.Fill(ds, "ExcelInfo");
  23:   
  24:  GridView1.DataSource = ds.Tables["ExcelInfo"].DefaultView;
  25:  GridView1.DataBind();

0 commenti