Reading Data From Excel File

Excel2007 works on the XML and there are several ways to retrive data from the Excel2007 file but below is the common method. Just changing the connection string ,lets us read other previous versions too.

  1. private DataSet openXLSFile(string filePath)
  2. {
  3. String sConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0";
  4. OleDbConnection objConn = new OleDbConnection(sConnectionString);
  5. objConn.Open();
  6. objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", objConn);
  7. objAdapter = new OleDbDataAdapter();
  8. objAdapter.SelectCommand = objCmdSelect;
  9. objDataset = new DataSet();
  10. objAdapter.Fill(objDataset, "CSVData");
  11. objConn.Close();
  12. return objDataset;
  13. }

Comments

Popular posts from this blog

SPFx: Develop using SharePoint Framework without Installing all the dependecies.

SharePoint Online: Elevated Permissions....with love

Powershell: Filling up an Existing Excel Sheet with data from SQL Server