private Microsoft.Office.Interop.Excel.Range GetSpecifiedRange(string matchStr, Microsoft.Office.Interop.Excel.Worksheet objWs)
{
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Range currentFind = null;
currentFind = objWs.get_Range("A1", "AM100").Find(matchStr, missing,
Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues,
Microsoft.Office.Interop.Excel.XlLookAt.xlPart,
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows,
Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, missing, missing);
return currentFind;
}
private void orderArtikelNummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
orderQtyTextBox.Focus();
e.Handled = true;
orderQtyTextBox.Select(0, orderQtyTextBox.Text.Length);
}
}
private void orderQtyTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
string File_name = "E:\\catalog.xls";
Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook oWB;
Microsoft.Office.Interop.Excel.Worksheet oSheet;
try
{
orderArtikelNummerTextBox.Focus();
e.Handled = true;
orderArtikelNummerTextBox.Select(0, orderArtikelNummerTextBox.Text.Length);
object missing = System.Reflection.Missing.Value;
oWB = oXL.Workbooks.Open(File_name, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing);
oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Worksheets[1];
Microsoft.Office.Interop.Excel.Range oRng = GetSpecifiedRange(orderArtikelNummerTextBox.SelectedText, oSheet);
if (oRng != null)
{
MessageBox.Show("Text found, position is Row:" + oRng.Row + " and column:" + oRng.Column);
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(this.orderDataGridView, orderArtikelNummerTextBox.Text, orderQtyTextBox.Text);
this.orderDataGridView.Rows.Add(row);
}
else
{
MessageBox.Show("Text is not found");
}
oWB.Close(false, missing, missing);
oSheet = null;
oWB = null;
oXL.Quit();
}
catch (Exception ex)
{
{
MessageBox.Show(" Exception caught." + ex);
}
}
}
}
Okay found how to read excel and get row and column number
Any suggestion how to count with the column number, Lets say +1 and than ask to excell the new counted column?
kind regards