Click here to Skip to main content
15,867,594 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to save data in c# Pin
Eddy Vluggen3-Jan-14 6:24
professionalEddy Vluggen3-Jan-14 6:24 
QuestionFilter list of classes by ComboBox. Harder than I thought. Pin
dudz artiaga2-Jan-14 4:10
dudz artiaga2-Jan-14 4:10 
AnswerRe: Filter list of classes by ComboBox. Harder than I thought. Pin
Ravi Bhavnani2-Jan-14 5:24
professionalRavi Bhavnani2-Jan-14 5:24 
AnswerRe: Filter list of classes by ComboBox. Harder than I thought. Pin
Eddy Vluggen2-Jan-14 9:06
professionalEddy Vluggen2-Jan-14 9:06 
Question[Solved] Getting non-null / non-zero cells from Excel using Cells.Find Pin
emma.sun.sts1-Jan-14 22:25
emma.sun.sts1-Jan-14 22:25 
AnswerRe: Getting non-null / non-zero cells from Excel using Cells.Find Pin
Eddy Vluggen2-Jan-14 8:12
professionalEddy Vluggen2-Jan-14 8:12 
GeneralRe: Getting non-null / non-zero cells from Excel using Cells.Find Pin
emma.sun.sts5-Jan-14 19:25
emma.sun.sts5-Jan-14 19:25 
AnswerRe: Getting non-null / non-zero cells from Excel using Cells.Find Pin
TnTinMn5-Jan-14 16:00
TnTinMn5-Jan-14 16:00 
The Find method is not appropriate for this type of filtered enumeration.

You could apply an Autofilter to the Range and then retrieve the Range.SpecialCells(Excel.XlCellType.xlCellTypeVisible) Range and iterate over that. However this is a lot work that would be easier to do in your own .Net code.

Once you have a Range object defined, you can retrieve the entire range as a two dimensional array of System.Object. Here is snippet showing how to do this.
C#
rng = ws.get_Range("A1", "A5");  // A1:A5
/* Excel returns a 2 dimensional array of the values even if you
 * only want to retrieve a range that represents a single row or
 * single column.
 *
 * The array is returned as a System.Object type, so casting is necessary.
 * Using an array of objects allows you can deal with multiple data types
 * and null values.
 *
 * If the range contains multiple areas (i.e.  A1:C4, F5:J20), only the first
 * area (A1:C4) will be returned.
 *
 * Excel works with one (1) based indexing not zero(0) based.  So the
 * lower bound of each array index will be one(1) not zero(0).
 *
 * The 1st Array Index corresponds to the row, and the second index to the
 * column. [R,C]
*/
object[,] retrievedarray = (object[,])rng.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault);

// Iterate over the array.  This is written to allow for a multicolumn Range.
for (Int32 col = retrievedarray.GetLowerBound(1); col <= retrievedarray.GetUpperBound(1); col++)
{
    for (Int32 row = retrievedarray.GetLowerBound(0); row <= retrievedarray.GetUpperBound(0); row++)
    {
        if (retrievedarray[row, col] is double)
        {
            double value = (double)retrievedarray[row, col];
            // do something with the value
            System.Diagnostics.Debug.WriteLine(value.ToString());
        }
        else if (retrievedarray[row, col] == null)
        {
            System.Diagnostics.Debug.WriteLine("null");
        }
    }
}

GeneralRe: Getting non-null / non-zero cells from Excel using Cells.Find Pin
emma.sun.sts14-Jan-14 21:16
emma.sun.sts14-Jan-14 21:16 
QuestionN-Tier C# Master Detail Pin
ahmed_one1-Jan-14 21:23
ahmed_one1-Jan-14 21:23 
AnswerRe: N-Tier C# Master Detail Pin
Eddy Vluggen2-Jan-14 8:07
professionalEddy Vluggen2-Jan-14 8:07 
QuestionRe: N-Tier C# Master Detail Pin
ahmed_one2-Jan-14 17:25
ahmed_one2-Jan-14 17:25 
AnswerRe: N-Tier C# Master Detail Pin
Eddy Vluggen3-Jan-14 6:37
professionalEddy Vluggen3-Jan-14 6:37 
GeneralRe: N-Tier C# Master Detail Pin
ahmed_one3-Jan-14 17:32
ahmed_one3-Jan-14 17:32 
GeneralRe: N-Tier C# Master Detail Pin
Eddy Vluggen4-Jan-14 5:28
professionalEddy Vluggen4-Jan-14 5:28 
GeneralRe: N-Tier C# Master Detail Pin
ahmed_one5-Jan-14 22:31
ahmed_one5-Jan-14 22:31 
GeneralRe: N-Tier C# Master Detail Pin
Eddy Vluggen7-Jan-14 9:18
professionalEddy Vluggen7-Jan-14 9:18 
QuestionMessage Closed Pin
1-Jan-14 17:24
Member 104982291-Jan-14 17:24 
AnswerRe: Seeking experienced Forex programmer to code EA in C# for PFSoft Protrader 3 Pin
Dave Kreskowiak1-Jan-14 17:52
mveDave Kreskowiak1-Jan-14 17:52 
GeneralRe: Seeking experienced Forex programmer to code EA in C# for PFSoft Protrader 3 Pin
OriginalGriff1-Jan-14 22:04
mveOriginalGriff1-Jan-14 22:04 
GeneralRe: Seeking experienced Forex programmer to code EA in C# for PFSoft Protrader 3 Pin
Dave Kreskowiak2-Jan-14 4:45
mveDave Kreskowiak2-Jan-14 4:45 
GeneralRe: Seeking experienced Forex programmer to code EA in C# for PFSoft Protrader 3 Pin
OriginalGriff2-Jan-14 5:06
mveOriginalGriff2-Jan-14 5:06 
Question.net Framework code Pin
Member 104981431-Jan-14 16:15
Member 104981431-Jan-14 16:15 
AnswerRe: .net Framework code Pin
Chris Quinn1-Jan-14 21:55
Chris Quinn1-Jan-14 21:55 
AnswerRe: .net Framework code Pin
OriginalGriff1-Jan-14 22:07
mveOriginalGriff1-Jan-14 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.