[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

looping through excel cell range

hey experts,
how do i loop through a range of cells?  something like this.

Excel.Range xlCells = xlSheet.get_Range("H4","P4");

foreach(Excel.cell loopCell in xlCells)
{
      loopCell.value2 = x;
}


thanks,

rye
0
ryeandi
Asked:
ryeandi
1 Solution
 
malharoneCommented:
if all you're trying to do is query the worksheet then ..


private DataSet TranslatExcelToDataset(string filePath)
{
      string ConnectionString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\"{0}\"; Extended Properties=\"Excel 8.0;HDR=No;IMEX=1;\"", filePath);
      OleDbConnection Connection = new OleDbConnection(ConnectionString);
      OleDbDataAdapter Adapter = new OleDbDataAdapter();
      OleDbCommand Command = new OleDbCommand("SELECT * FROM [Sheet1$]", Connection);
      DataSet DS = new DataSet("Table");
      Adapter.SelectCommand = Command;
      Adapter.Fill(DS);
      return DS;
}



hope this helps
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now