If found return true;
for( int i=1; i
{
this.excelWorksheet =
(Excel.Worksheet)excelSheets.get_Item((object)i);
if( this.excelWorksheet.Name.Equals(worksheetName) )
{
this.excelWorksheet.Activate();
ATP_SHEET_FOUND = true;
return ATP_SHEET_FOUND;
}
}
}
return ATP_SHEET_FOUND;
}
#endregion
…
The above code demonstrates how to get all worksheets belonging to a workbook and getting a specific worksheet to extract data from. GetExcelSheets() gets all the sheets. FindExcelATPWorkSheet(string worksheetName) searches for worksheets with the name worksheetName.
…
///
/// Vahe Karamian – 03/22/2005 – Get Range from Worksheet
/// Return content of range from the selected range
///
/// Range parameter: Example, GetRange(“A1:D10″)
#region GET RANGE
public string[] GetRange(string range)
{
Excel.Range workingRangeCells = excelWorksheet.get_Range(range,Type.Missing);
//workingRangeCells.Select();
System.Array array = (System.Array)workingRangeCells.Cells.Value2;
string[] arrayS = this.ConvertToStringArray(array);
return arrayS;
}
#endregion
…
GetRange(string range) is the function that actually retrieves the data from the Excel sheet and we convert the returned values into a string[]. This is done by the next function call: this.ConvertToStringArray(array). Then the string[] is passed back to the caller who can consume it in any way they want.
…
///
/// Vahe Karamian – 03/22/2005 – Convert To String Array
/// Convert System.Array into string[]
///
/// Values from range object
/// String[]
#region CONVERT TO STRING ARRAY
private string[] ConvertToStringArray(System.Array values)
{
string[] newArray = new string[values.Length];
int index = 0;
for ( int i = values.GetLowerBound(0); i
{
for ( int j = values.GetLowerBound(1); j
{
if(values.GetValue(i,j)==null)
{
newArray[index]=”";
}
else
{
newArray[index]=(string)values.GetValue(i,j).ToString();
}
index++;
}
}
return newArray;
}
#endregion
}
And the final code portion: ConvertToStringArray(System.Array values) will take the array passed from GetRange(…) to put it into a string array and pass it back.
We have reached the end of our object.
marketing automation