D
Dwight Trumbower
There has to be a better way than the following code. My main area of
question is getting data from a cell.
This following statement is the only way I can get it to work. Just seems
like to much clutter.
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
private void ProcessToss( string[] filePaths)
{
int MaxRow;
string Col5, Col6, Col12, LookUp;
string ConvType;
XL._Worksheet CurWorkSheet;
using (XCel xlHand = new XCel()) // using a class that handles excel
connection
{
xlHand.Get_NewApp();
foreach( string TossFilePath in filePaths) // Can process multiple excel
files
{
xlHand.OpenFile (TossFilePath);
xlHand.ActivateWS(1);
MaxRow = xlHand.LastRow - 8 ;
CurWorkSheet = (XL._Worksheet )xlHand.CurrentSheet;
for ( int Row =9; Row <= MaxRow; Row++)
{
xlHand.StatusBar = string.Format("Current row is {0}", Row);
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
if( ConvType == "T")
{
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2 == null)
Col5 = "";
else
Col5 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString() == null)
Col6 = "";
else
Col6 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString() == null)
Col12 = "";
else
Col12 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString();
LookUp = ConvType + Col5 + Col6 +Col12;
if( this.textTable.Contains(LookUp))
{
CurWorkSheet.Cells[ Row, 4 ] = this.textTable[LookUp].ToString ();
}
}
}
xlHand.SaveWB (TossFilePath.Substring (0,18) + "UniqueText.xls");
xlHand.StatusBar = "";
}
}
}
Thanks
question is getting data from a cell.
This following statement is the only way I can get it to work. Just seems
like to much clutter.
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
private void ProcessToss( string[] filePaths)
{
int MaxRow;
string Col5, Col6, Col12, LookUp;
string ConvType;
XL._Worksheet CurWorkSheet;
using (XCel xlHand = new XCel()) // using a class that handles excel
connection
{
xlHand.Get_NewApp();
foreach( string TossFilePath in filePaths) // Can process multiple excel
files
{
xlHand.OpenFile (TossFilePath);
xlHand.ActivateWS(1);
MaxRow = xlHand.LastRow - 8 ;
CurWorkSheet = (XL._Worksheet )xlHand.CurrentSheet;
for ( int Row =9; Row <= MaxRow; Row++)
{
xlHand.StatusBar = string.Format("Current row is {0}", Row);
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
if( ConvType == "T")
{
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2 == null)
Col5 = "";
else
Col5 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString() == null)
Col6 = "";
else
Col6 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString() == null)
Col12 = "";
else
Col12 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString();
LookUp = ConvType + Col5 + Col6 +Col12;
if( this.textTable.Contains(LookUp))
{
CurWorkSheet.Cells[ Row, 4 ] = this.textTable[LookUp].ToString ();
}
}
}
xlHand.SaveWB (TossFilePath.Substring (0,18) + "UniqueText.xls");
xlHand.StatusBar = "";
}
}
}
Thanks