Solved

looping through excel cell range

Posted on 2004-03-29
3
363 Views
Last Modified: 2010-04-15
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
Comment
Question by:ryeandi
3 Comments
 
LVL 9

Accepted Solution

by:
malharone earned 20 total points
ID: 10719736
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now